@hasna/connectors 0.5.8 → 0.5.9

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.
Files changed (137) hide show
  1. package/bin/index.js +57 -1
  2. package/bin/mcp.js +57 -1
  3. package/bin/serve.js +56 -0
  4. package/connectors/connect-chargebee/.env.example +11 -0
  5. package/connectors/connect-chargebee/CLAUDE.md +272 -0
  6. package/connectors/connect-chargebee/README.md +193 -0
  7. package/connectors/connect-chargebee/package.json +51 -0
  8. package/connectors/connect-chargebee/scripts/release.ts +179 -0
  9. package/connectors/connect-chargebee/src/api/client.ts +213 -0
  10. package/connectors/connect-chargebee/src/api/example.ts +48 -0
  11. package/connectors/connect-chargebee/src/api/index.ts +51 -0
  12. package/connectors/connect-chargebee/src/cli/index.ts +254 -0
  13. package/connectors/connect-chargebee/src/index.ts +103 -0
  14. package/connectors/connect-chargebee/src/types/index.ts +237 -0
  15. package/connectors/connect-chargebee/src/utils/auth.ts +274 -0
  16. package/connectors/connect-chargebee/src/utils/bulk.ts +212 -0
  17. package/connectors/connect-chargebee/src/utils/config.ts +326 -0
  18. package/connectors/connect-chargebee/src/utils/output.ts +175 -0
  19. package/connectors/connect-chargebee/src/utils/settings.ts +114 -0
  20. package/connectors/connect-chargebee/src/utils/storage.ts +198 -0
  21. package/connectors/connect-chargebee/tsconfig.json +16 -0
  22. package/connectors/connect-databricks/.env.example +11 -0
  23. package/connectors/connect-databricks/CLAUDE.md +272 -0
  24. package/connectors/connect-databricks/README.md +193 -0
  25. package/connectors/connect-databricks/package.json +51 -0
  26. package/connectors/connect-databricks/scripts/release.ts +179 -0
  27. package/connectors/connect-databricks/src/api/client.ts +213 -0
  28. package/connectors/connect-databricks/src/api/example.ts +48 -0
  29. package/connectors/connect-databricks/src/api/index.ts +51 -0
  30. package/connectors/connect-databricks/src/cli/index.ts +254 -0
  31. package/connectors/connect-databricks/src/index.ts +103 -0
  32. package/connectors/connect-databricks/src/types/index.ts +237 -0
  33. package/connectors/connect-databricks/src/utils/auth.ts +274 -0
  34. package/connectors/connect-databricks/src/utils/bulk.ts +212 -0
  35. package/connectors/connect-databricks/src/utils/config.ts +326 -0
  36. package/connectors/connect-databricks/src/utils/output.ts +175 -0
  37. package/connectors/connect-databricks/src/utils/settings.ts +114 -0
  38. package/connectors/connect-databricks/src/utils/storage.ts +198 -0
  39. package/connectors/connect-databricks/tsconfig.json +16 -0
  40. package/connectors/connect-datadog/.env.example +11 -0
  41. package/connectors/connect-datadog/CLAUDE.md +170 -0
  42. package/connectors/connect-datadog/README.md +193 -0
  43. package/connectors/connect-datadog/package.json +53 -0
  44. package/connectors/connect-datadog/src/api/client.ts +150 -0
  45. package/connectors/connect-datadog/src/api/index.ts +537 -0
  46. package/connectors/connect-datadog/src/cli/index.ts +958 -0
  47. package/connectors/connect-datadog/src/index.ts +26 -0
  48. package/connectors/connect-datadog/src/types/index.ts +654 -0
  49. package/connectors/connect-datadog/src/utils/config.ts +219 -0
  50. package/connectors/connect-datadog/src/utils/output.ts +119 -0
  51. package/connectors/connect-datadog/tsconfig.json +16 -0
  52. package/connectors/connect-fathom/.env.example +11 -0
  53. package/connectors/connect-fathom/CLAUDE.md +272 -0
  54. package/connectors/connect-fathom/README.md +193 -0
  55. package/connectors/connect-fathom/package.json +51 -0
  56. package/connectors/connect-fathom/scripts/release.ts +179 -0
  57. package/connectors/connect-fathom/src/api/client.ts +213 -0
  58. package/connectors/connect-fathom/src/api/example.ts +48 -0
  59. package/connectors/connect-fathom/src/api/index.ts +51 -0
  60. package/connectors/connect-fathom/src/cli/index.ts +254 -0
  61. package/connectors/connect-fathom/src/index.ts +103 -0
  62. package/connectors/connect-fathom/src/types/index.ts +237 -0
  63. package/connectors/connect-fathom/src/utils/auth.ts +274 -0
  64. package/connectors/connect-fathom/src/utils/bulk.ts +212 -0
  65. package/connectors/connect-fathom/src/utils/config.ts +326 -0
  66. package/connectors/connect-fathom/src/utils/output.ts +175 -0
  67. package/connectors/connect-fathom/src/utils/settings.ts +114 -0
  68. package/connectors/connect-fathom/src/utils/storage.ts +198 -0
  69. package/connectors/connect-fathom/tsconfig.json +16 -0
  70. package/connectors/connect-grafana/.env.example +11 -0
  71. package/connectors/connect-grafana/CLAUDE.md +272 -0
  72. package/connectors/connect-grafana/README.md +193 -0
  73. package/connectors/connect-grafana/package.json +51 -0
  74. package/connectors/connect-grafana/scripts/release.ts +179 -0
  75. package/connectors/connect-grafana/src/api/client.ts +213 -0
  76. package/connectors/connect-grafana/src/api/example.ts +48 -0
  77. package/connectors/connect-grafana/src/api/index.ts +51 -0
  78. package/connectors/connect-grafana/src/cli/index.ts +254 -0
  79. package/connectors/connect-grafana/src/index.ts +103 -0
  80. package/connectors/connect-grafana/src/types/index.ts +237 -0
  81. package/connectors/connect-grafana/src/utils/auth.ts +274 -0
  82. package/connectors/connect-grafana/src/utils/bulk.ts +212 -0
  83. package/connectors/connect-grafana/src/utils/config.ts +326 -0
  84. package/connectors/connect-grafana/src/utils/output.ts +175 -0
  85. package/connectors/connect-grafana/src/utils/settings.ts +114 -0
  86. package/connectors/connect-grafana/src/utils/storage.ts +198 -0
  87. package/connectors/connect-grafana/tsconfig.json +16 -0
  88. package/connectors/connect-paddle/.env.example +11 -0
  89. package/connectors/connect-paddle/CLAUDE.md +272 -0
  90. package/connectors/connect-paddle/README.md +193 -0
  91. package/connectors/connect-paddle/package.json +51 -0
  92. package/connectors/connect-paddle/scripts/release.ts +179 -0
  93. package/connectors/connect-paddle/src/api/client.ts +213 -0
  94. package/connectors/connect-paddle/src/api/example.ts +48 -0
  95. package/connectors/connect-paddle/src/api/index.ts +51 -0
  96. package/connectors/connect-paddle/src/cli/index.ts +254 -0
  97. package/connectors/connect-paddle/src/index.ts +103 -0
  98. package/connectors/connect-paddle/src/types/index.ts +237 -0
  99. package/connectors/connect-paddle/src/utils/auth.ts +274 -0
  100. package/connectors/connect-paddle/src/utils/bulk.ts +212 -0
  101. package/connectors/connect-paddle/src/utils/config.ts +326 -0
  102. package/connectors/connect-paddle/src/utils/output.ts +175 -0
  103. package/connectors/connect-paddle/src/utils/settings.ts +114 -0
  104. package/connectors/connect-paddle/src/utils/storage.ts +198 -0
  105. package/connectors/connect-paddle/tsconfig.json +16 -0
  106. package/connectors/connect-snowflake/.env.example +11 -0
  107. package/connectors/connect-snowflake/CLAUDE.md +272 -0
  108. package/connectors/connect-snowflake/README.md +193 -0
  109. package/connectors/connect-snowflake/package.json +51 -0
  110. package/connectors/connect-snowflake/scripts/release.ts +179 -0
  111. package/connectors/connect-snowflake/src/api/client.ts +213 -0
  112. package/connectors/connect-snowflake/src/api/example.ts +48 -0
  113. package/connectors/connect-snowflake/src/api/index.ts +51 -0
  114. package/connectors/connect-snowflake/src/cli/index.ts +254 -0
  115. package/connectors/connect-snowflake/src/index.ts +103 -0
  116. package/connectors/connect-snowflake/src/types/index.ts +237 -0
  117. package/connectors/connect-snowflake/src/utils/auth.ts +274 -0
  118. package/connectors/connect-snowflake/src/utils/bulk.ts +212 -0
  119. package/connectors/connect-snowflake/src/utils/config.ts +326 -0
  120. package/connectors/connect-snowflake/src/utils/output.ts +175 -0
  121. package/connectors/connect-snowflake/src/utils/settings.ts +114 -0
  122. package/connectors/connect-snowflake/src/utils/storage.ts +198 -0
  123. package/connectors/connect-snowflake/tsconfig.json +16 -0
  124. package/connectors/connect-square/.env.example +11 -0
  125. package/connectors/connect-square/CLAUDE.md +128 -0
  126. package/connectors/connect-square/README.md +193 -0
  127. package/connectors/connect-square/package.json +52 -0
  128. package/connectors/connect-square/src/api/client.ts +152 -0
  129. package/connectors/connect-square/src/api/index.ts +343 -0
  130. package/connectors/connect-square/src/cli/index.ts +579 -0
  131. package/connectors/connect-square/src/index.ts +21 -0
  132. package/connectors/connect-square/src/types/index.ts +809 -0
  133. package/connectors/connect-square/src/utils/config.ts +209 -0
  134. package/connectors/connect-square/src/utils/output.ts +119 -0
  135. package/connectors/connect-square/tsconfig.json +16 -0
  136. package/dist/index.js +56 -0
  137. package/package.json +1 -1
@@ -0,0 +1,579 @@
1
+ #!/usr/bin/env bun
2
+ import { Command } from 'commander';
3
+ import chalk from 'chalk';
4
+ import { Square, SquareClient } from '../api';
5
+ import {
6
+ getAccessToken,
7
+ setAccessToken,
8
+ getBaseUrl,
9
+ setBaseUrl,
10
+ clearConfig,
11
+ getConfigDir,
12
+ setProfileOverride,
13
+ getCurrentProfile,
14
+ setCurrentProfile,
15
+ listProfiles,
16
+ createProfile,
17
+ deleteProfile,
18
+ profileExists,
19
+ loadProfile,
20
+ } from '../utils/config';
21
+ import type { OutputFormat } from '../utils/output';
22
+ import { success, error, info, print } from '../utils/output';
23
+
24
+ const CONNECTOR_NAME = 'connect-square';
25
+ const VERSION = '0.0.1';
26
+
27
+ const program = new Command();
28
+
29
+ program
30
+ .name(CONNECTOR_NAME)
31
+ .description('Square connector - Payments, orders, customers, and catalog API')
32
+ .version(VERSION)
33
+ .option('-k, --access-token <token>', 'Access token (overrides config)')
34
+ .option('-f, --format <format>', 'Output format (json, pretty)', 'pretty')
35
+ .option('-p, --profile <profile>', 'Use a specific profile')
36
+ .option('--sandbox', 'Use Square sandbox environment')
37
+ .hook('preAction', (thisCommand) => {
38
+ const opts = thisCommand.opts();
39
+ // Set profile override before any command runs
40
+ if (opts.profile) {
41
+ if (!profileExists(opts.profile)) {
42
+ error(`Profile "${opts.profile}" does not exist. Create it with "${CONNECTOR_NAME} profile create ${opts.profile}"`);
43
+ process.exit(1);
44
+ }
45
+ setProfileOverride(opts.profile);
46
+ }
47
+ // Set access token from flag if provided
48
+ if (opts.accessToken) {
49
+ process.env.SQUARE_ACCESS_TOKEN = opts.accessToken;
50
+ }
51
+ // Set sandbox URL if flag provided
52
+ if (opts.sandbox) {
53
+ process.env.SQUARE_BASE_URL = SquareClient.getSandboxUrl();
54
+ }
55
+ });
56
+
57
+ // Helper to get output format
58
+ function getFormat(cmd: Command): OutputFormat {
59
+ const parent = cmd.parent;
60
+ return (parent?.opts().format || 'pretty') as OutputFormat;
61
+ }
62
+
63
+ // Helper to get authenticated client
64
+ function getClient(): Square {
65
+ const accessToken = getAccessToken();
66
+ if (!accessToken) {
67
+ error(`No access token configured. Run "${CONNECTOR_NAME} config set-token <token>" or set SQUARE_ACCESS_TOKEN environment variable.`);
68
+ process.exit(1);
69
+ }
70
+ const baseUrl = getBaseUrl();
71
+ return new Square({ accessToken, baseUrl });
72
+ }
73
+
74
+ // ============================================
75
+ // Profile Commands
76
+ // ============================================
77
+ const profileCmd = program
78
+ .command('profile')
79
+ .description('Manage configuration profiles');
80
+
81
+ profileCmd
82
+ .command('list')
83
+ .description('List all profiles')
84
+ .action(() => {
85
+ const profiles = listProfiles();
86
+ const current = getCurrentProfile();
87
+
88
+ if (profiles.length === 0) {
89
+ info('No profiles found. Use "profile create <name>" to create one.');
90
+ return;
91
+ }
92
+
93
+ success(`Profiles:`);
94
+ profiles.forEach(p => {
95
+ const isActive = p === current ? chalk.green(' (active)') : '';
96
+ console.log(` ${p}${isActive}`);
97
+ });
98
+ });
99
+
100
+ profileCmd
101
+ .command('use <name>')
102
+ .description('Switch to a profile')
103
+ .action((name: string) => {
104
+ if (!profileExists(name)) {
105
+ error(`Profile "${name}" does not exist. Create it with "profile create ${name}"`);
106
+ process.exit(1);
107
+ }
108
+ setCurrentProfile(name);
109
+ success(`Switched to profile: ${name}`);
110
+ });
111
+
112
+ profileCmd
113
+ .command('create <name>')
114
+ .description('Create a new profile')
115
+ .option('--access-token <token>', 'Access token')
116
+ .option('--sandbox', 'Use sandbox environment')
117
+ .option('--use', 'Switch to this profile after creation')
118
+ .action((name: string, opts) => {
119
+ if (profileExists(name)) {
120
+ error(`Profile "${name}" already exists`);
121
+ process.exit(1);
122
+ }
123
+
124
+ createProfile(name, {
125
+ accessToken: opts.accessToken,
126
+ baseUrl: opts.sandbox ? SquareClient.getSandboxUrl() : undefined,
127
+ });
128
+ success(`Profile "${name}" created`);
129
+
130
+ if (opts.use) {
131
+ setCurrentProfile(name);
132
+ info(`Switched to profile: ${name}`);
133
+ }
134
+ });
135
+
136
+ profileCmd
137
+ .command('delete <name>')
138
+ .description('Delete a profile')
139
+ .action((name: string) => {
140
+ if (name === 'default') {
141
+ error('Cannot delete the default profile');
142
+ process.exit(1);
143
+ }
144
+ if (deleteProfile(name)) {
145
+ success(`Profile "${name}" deleted`);
146
+ } else {
147
+ error(`Profile "${name}" not found`);
148
+ process.exit(1);
149
+ }
150
+ });
151
+
152
+ profileCmd
153
+ .command('show [name]')
154
+ .description('Show profile configuration')
155
+ .action((name?: string) => {
156
+ const profileName = name || getCurrentProfile();
157
+ const config = loadProfile(profileName);
158
+ const active = getCurrentProfile();
159
+
160
+ console.log(chalk.bold(`Profile: ${profileName}${profileName === active ? chalk.green(' (active)') : ''}`));
161
+ info(`Access Token: ${config.accessToken ? `${config.accessToken.substring(0, 8)}...` : chalk.gray('not set')}`);
162
+ info(`Base URL: ${config.baseUrl || chalk.gray('production (default)')}`);
163
+ });
164
+
165
+ // ============================================
166
+ // Config Commands
167
+ // ============================================
168
+ const configCmd = program
169
+ .command('config')
170
+ .description('Manage CLI configuration (for active profile)');
171
+
172
+ configCmd
173
+ .command('set-token <accessToken>')
174
+ .description('Set access token')
175
+ .action((accessToken: string) => {
176
+ setAccessToken(accessToken);
177
+ success(`Access token saved to profile: ${getCurrentProfile()}`);
178
+ });
179
+
180
+ configCmd
181
+ .command('set-url <baseUrl>')
182
+ .description('Set base URL (use "sandbox" for sandbox environment)')
183
+ .action((baseUrl: string) => {
184
+ const url = baseUrl === 'sandbox' ? SquareClient.getSandboxUrl() : baseUrl;
185
+ setBaseUrl(url);
186
+ success(`Base URL saved to profile: ${getCurrentProfile()}`);
187
+ });
188
+
189
+ configCmd
190
+ .command('show')
191
+ .description('Show current configuration')
192
+ .action(() => {
193
+ const profileName = getCurrentProfile();
194
+ const accessToken = getAccessToken();
195
+ const baseUrl = getBaseUrl();
196
+
197
+ console.log(chalk.bold(`Active Profile: ${profileName}`));
198
+ info(`Config directory: ${getConfigDir()}`);
199
+ info(`Access Token: ${accessToken ? `${accessToken.substring(0, 8)}...` : chalk.gray('not set')}`);
200
+ info(`Base URL: ${baseUrl || 'production (default)'}`);
201
+ });
202
+
203
+ configCmd
204
+ .command('clear')
205
+ .description('Clear configuration for active profile')
206
+ .action(() => {
207
+ clearConfig();
208
+ success(`Configuration cleared for profile: ${getCurrentProfile()}`);
209
+ });
210
+
211
+ // ============================================
212
+ // Location Commands
213
+ // ============================================
214
+ const locationCmd = program
215
+ .command('location')
216
+ .description('Manage Square locations');
217
+
218
+ locationCmd
219
+ .command('list')
220
+ .description('List all locations')
221
+ .action(async () => {
222
+ try {
223
+ const client = getClient();
224
+ const result = await client.listLocations();
225
+ print(result, getFormat(locationCmd));
226
+ } catch (err) {
227
+ error(String(err));
228
+ process.exit(1);
229
+ }
230
+ });
231
+
232
+ locationCmd
233
+ .command('get <id>')
234
+ .description('Get a location by ID')
235
+ .action(async (id: string) => {
236
+ try {
237
+ const client = getClient();
238
+ const result = await client.getLocation(id);
239
+ print(result, getFormat(locationCmd));
240
+ } catch (err) {
241
+ error(String(err));
242
+ process.exit(1);
243
+ }
244
+ });
245
+
246
+ // ============================================
247
+ // Customer Commands
248
+ // ============================================
249
+ const customerCmd = program
250
+ .command('customer')
251
+ .description('Manage customers');
252
+
253
+ customerCmd
254
+ .command('list')
255
+ .description('List customers')
256
+ .option('-l, --limit <number>', 'Maximum results', '20')
257
+ .option('--cursor <cursor>', 'Pagination cursor')
258
+ .action(async (opts) => {
259
+ try {
260
+ const client = getClient();
261
+ const result = await client.listCustomers({
262
+ limit: parseInt(opts.limit),
263
+ cursor: opts.cursor,
264
+ });
265
+ print(result, getFormat(customerCmd));
266
+ } catch (err) {
267
+ error(String(err));
268
+ process.exit(1);
269
+ }
270
+ });
271
+
272
+ customerCmd
273
+ .command('get <id>')
274
+ .description('Get a customer by ID')
275
+ .action(async (id: string) => {
276
+ try {
277
+ const client = getClient();
278
+ const result = await client.getCustomer(id);
279
+ print(result, getFormat(customerCmd));
280
+ } catch (err) {
281
+ error(String(err));
282
+ process.exit(1);
283
+ }
284
+ });
285
+
286
+ customerCmd
287
+ .command('create')
288
+ .description('Create a new customer')
289
+ .option('--given-name <name>', 'First name')
290
+ .option('--family-name <name>', 'Last name')
291
+ .option('--email <email>', 'Email address')
292
+ .option('--phone <phone>', 'Phone number')
293
+ .option('--company <company>', 'Company name')
294
+ .option('--note <note>', 'Note')
295
+ .action(async (opts) => {
296
+ try {
297
+ const client = getClient();
298
+ const result = await client.createCustomer({
299
+ given_name: opts.givenName,
300
+ family_name: opts.familyName,
301
+ email_address: opts.email,
302
+ phone_number: opts.phone,
303
+ company_name: opts.company,
304
+ note: opts.note,
305
+ });
306
+ success('Customer created!');
307
+ print(result, getFormat(customerCmd));
308
+ } catch (err) {
309
+ error(String(err));
310
+ process.exit(1);
311
+ }
312
+ });
313
+
314
+ customerCmd
315
+ .command('delete <id>')
316
+ .description('Delete a customer')
317
+ .action(async (id: string) => {
318
+ try {
319
+ const client = getClient();
320
+ await client.deleteCustomer(id);
321
+ success(`Customer ${id} deleted`);
322
+ } catch (err) {
323
+ error(String(err));
324
+ process.exit(1);
325
+ }
326
+ });
327
+
328
+ customerCmd
329
+ .command('search')
330
+ .description('Search customers')
331
+ .option('--email <email>', 'Search by email')
332
+ .option('--phone <phone>', 'Search by phone')
333
+ .option('-l, --limit <number>', 'Maximum results', '20')
334
+ .action(async (opts) => {
335
+ try {
336
+ const client = getClient();
337
+ const filter: Record<string, { exact?: string }> = {};
338
+ if (opts.email) filter.email_address = { exact: opts.email };
339
+ if (opts.phone) filter.phone_number = { exact: opts.phone };
340
+
341
+ const result = await client.searchCustomers({
342
+ limit: parseInt(opts.limit),
343
+ query: Object.keys(filter).length > 0 ? { filter } : undefined,
344
+ });
345
+ print(result, getFormat(customerCmd));
346
+ } catch (err) {
347
+ error(String(err));
348
+ process.exit(1);
349
+ }
350
+ });
351
+
352
+ // ============================================
353
+ // Payment Commands
354
+ // ============================================
355
+ const paymentCmd = program
356
+ .command('payment')
357
+ .description('Manage payments');
358
+
359
+ paymentCmd
360
+ .command('list')
361
+ .description('List payments')
362
+ .option('-l, --limit <number>', 'Maximum results', '20')
363
+ .option('--location <id>', 'Filter by location ID')
364
+ .option('--begin <date>', 'Start date (ISO 8601)')
365
+ .option('--end <date>', 'End date (ISO 8601)')
366
+ .option('--cursor <cursor>', 'Pagination cursor')
367
+ .action(async (opts) => {
368
+ try {
369
+ const client = getClient();
370
+ const result = await client.listPayments({
371
+ limit: parseInt(opts.limit),
372
+ location_id: opts.location,
373
+ begin_time: opts.begin,
374
+ end_time: opts.end,
375
+ cursor: opts.cursor,
376
+ });
377
+ print(result, getFormat(paymentCmd));
378
+ } catch (err) {
379
+ error(String(err));
380
+ process.exit(1);
381
+ }
382
+ });
383
+
384
+ paymentCmd
385
+ .command('get <id>')
386
+ .description('Get a payment by ID')
387
+ .action(async (id: string) => {
388
+ try {
389
+ const client = getClient();
390
+ const result = await client.getPayment(id);
391
+ print(result, getFormat(paymentCmd));
392
+ } catch (err) {
393
+ error(String(err));
394
+ process.exit(1);
395
+ }
396
+ });
397
+
398
+ paymentCmd
399
+ .command('cancel <id>')
400
+ .description('Cancel a payment')
401
+ .action(async (id: string) => {
402
+ try {
403
+ const client = getClient();
404
+ const result = await client.cancelPayment(id);
405
+ success('Payment cancelled!');
406
+ print(result, getFormat(paymentCmd));
407
+ } catch (err) {
408
+ error(String(err));
409
+ process.exit(1);
410
+ }
411
+ });
412
+
413
+ paymentCmd
414
+ .command('complete <id>')
415
+ .description('Complete a payment')
416
+ .action(async (id: string) => {
417
+ try {
418
+ const client = getClient();
419
+ const result = await client.completePayment(id);
420
+ success('Payment completed!');
421
+ print(result, getFormat(paymentCmd));
422
+ } catch (err) {
423
+ error(String(err));
424
+ process.exit(1);
425
+ }
426
+ });
427
+
428
+ // ============================================
429
+ // Order Commands
430
+ // ============================================
431
+ const orderCmd = program
432
+ .command('order')
433
+ .description('Manage orders');
434
+
435
+ orderCmd
436
+ .command('get <id>')
437
+ .description('Get an order by ID')
438
+ .action(async (id: string) => {
439
+ try {
440
+ const client = getClient();
441
+ const result = await client.getOrder(id);
442
+ print(result, getFormat(orderCmd));
443
+ } catch (err) {
444
+ error(String(err));
445
+ process.exit(1);
446
+ }
447
+ });
448
+
449
+ orderCmd
450
+ .command('search')
451
+ .description('Search orders')
452
+ .requiredOption('--location <ids>', 'Location IDs (comma-separated)')
453
+ .option('-l, --limit <number>', 'Maximum results', '20')
454
+ .option('--state <states>', 'Filter by states (comma-separated: OPEN,COMPLETED,CANCELED,DRAFT)')
455
+ .option('--customer <id>', 'Filter by customer ID')
456
+ .option('--cursor <cursor>', 'Pagination cursor')
457
+ .action(async (opts) => {
458
+ try {
459
+ const client = getClient();
460
+ const locationIds = opts.location.split(',').map((s: string) => s.trim());
461
+
462
+ const query: {
463
+ filter?: {
464
+ state_filter?: { states: string[] };
465
+ customer_filter?: { customer_ids: string[] };
466
+ };
467
+ } = {};
468
+
469
+ if (opts.state) {
470
+ query.filter = query.filter || {};
471
+ query.filter.state_filter = { states: opts.state.split(',').map((s: string) => s.trim()) };
472
+ }
473
+ if (opts.customer) {
474
+ query.filter = query.filter || {};
475
+ query.filter.customer_filter = { customer_ids: [opts.customer] };
476
+ }
477
+
478
+ const result = await client.searchOrders({
479
+ location_ids: locationIds,
480
+ limit: parseInt(opts.limit),
481
+ query: Object.keys(query).length > 0 ? query : undefined,
482
+ cursor: opts.cursor,
483
+ });
484
+ print(result, getFormat(orderCmd));
485
+ } catch (err) {
486
+ error(String(err));
487
+ process.exit(1);
488
+ }
489
+ });
490
+
491
+ // ============================================
492
+ // Catalog Commands
493
+ // ============================================
494
+ const catalogCmd = program
495
+ .command('catalog')
496
+ .description('Manage catalog');
497
+
498
+ catalogCmd
499
+ .command('list')
500
+ .description('List catalog objects')
501
+ .option('--types <types>', 'Object types (comma-separated: ITEM,CATEGORY,TAX,DISCOUNT,MODIFIER_LIST)')
502
+ .option('--cursor <cursor>', 'Pagination cursor')
503
+ .action(async (opts) => {
504
+ try {
505
+ const client = getClient();
506
+ const result = await client.listCatalog({
507
+ types: opts.types,
508
+ cursor: opts.cursor,
509
+ });
510
+ print(result, getFormat(catalogCmd));
511
+ } catch (err) {
512
+ error(String(err));
513
+ process.exit(1);
514
+ }
515
+ });
516
+
517
+ catalogCmd
518
+ .command('get <id>')
519
+ .description('Get a catalog object by ID')
520
+ .option('--include-related', 'Include related objects')
521
+ .action(async (id: string, opts) => {
522
+ try {
523
+ const client = getClient();
524
+ const result = await client.getCatalogObject(id, {
525
+ include_related_objects: opts.includeRelated,
526
+ });
527
+ print(result, getFormat(catalogCmd));
528
+ } catch (err) {
529
+ error(String(err));
530
+ process.exit(1);
531
+ }
532
+ });
533
+
534
+ catalogCmd
535
+ .command('search')
536
+ .description('Search catalog')
537
+ .option('--text <keywords>', 'Search by keywords')
538
+ .option('--types <types>', 'Object types (comma-separated)')
539
+ .option('-l, --limit <number>', 'Maximum results', '20')
540
+ .option('--cursor <cursor>', 'Pagination cursor')
541
+ .action(async (opts) => {
542
+ try {
543
+ const client = getClient();
544
+ const query: { text_query?: { keywords: string[] } } = {};
545
+
546
+ if (opts.text) {
547
+ query.text_query = { keywords: opts.text.split(' ') };
548
+ }
549
+
550
+ const result = await client.searchCatalog({
551
+ object_types: opts.types ? opts.types.split(',').map((s: string) => s.trim()) : undefined,
552
+ limit: parseInt(opts.limit),
553
+ query: Object.keys(query).length > 0 ? query : undefined,
554
+ cursor: opts.cursor,
555
+ });
556
+ print(result, getFormat(catalogCmd));
557
+ } catch (err) {
558
+ error(String(err));
559
+ process.exit(1);
560
+ }
561
+ });
562
+
563
+ catalogCmd
564
+ .command('delete <id>')
565
+ .description('Delete a catalog object')
566
+ .action(async (id: string) => {
567
+ try {
568
+ const client = getClient();
569
+ const result = await client.deleteCatalogObject(id);
570
+ success('Catalog object deleted!');
571
+ print(result, getFormat(catalogCmd));
572
+ } catch (err) {
573
+ error(String(err));
574
+ process.exit(1);
575
+ }
576
+ });
577
+
578
+ // Parse and execute
579
+ program.parse();
@@ -0,0 +1,21 @@
1
+ // Square Connector
2
+ // TypeScript wrapper for Square payments, orders, customers, and catalog API
3
+
4
+ export { Square } from './api';
5
+ export * from './types';
6
+ export { SquareClient } from './api';
7
+
8
+ export {
9
+ getAccessToken,
10
+ setAccessToken,
11
+ getBaseUrl,
12
+ setBaseUrl,
13
+ getCurrentProfile,
14
+ setCurrentProfile,
15
+ listProfiles,
16
+ createProfile,
17
+ deleteProfile,
18
+ loadProfile,
19
+ saveProfile,
20
+ clearConfig,
21
+ } from './utils/config';