xero-cli-bin 0.0.0

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/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # xero-cli-bin
2
+
3
+ Xero Accounting API 命令行工具 - 透過 npx 直接使用
4
+
5
+ ## 快速開始
6
+
7
+ ### 無需安裝(推薦)
8
+
9
+ ```bash
10
+ # 直接使用
11
+ npx xero-cli-bin --version
12
+ npx xero-cli-bin auth
13
+ npx xero-cli-bin invoices list
14
+ ```
15
+
16
+ ### 全域安裝(可選)
17
+
18
+ ```bash
19
+ npm install -g xero-cli-bin
20
+ xero-cli --version
21
+ ```
22
+
23
+ ## 功能特點
24
+
25
+ - 🔐 OAuth2 PKCE 認證
26
+ - 📄 發票管理(查詢、取得)
27
+ - 👥 聯絡人管理
28
+ - 🏦 帳戶查詢
29
+ - 💰 付款記錄查詢
30
+ - 📊 貸項通知單查詢
31
+ - 🔄 Token 自動更新
32
+ - 🔒 加密儲存憑證
33
+
34
+ ## 系統需求
35
+
36
+ - Node.js >= 14.0.0
37
+ - 支援平台:
38
+ - Windows (x64, arm64)
39
+ - macOS (x64, arm64)
40
+ - Linux (x64, arm64)
41
+
42
+ ## 使用說明
43
+
44
+ ### 1. 認證
45
+
46
+ ```bash
47
+ npx xero-cli-bin auth
48
+ ```
49
+
50
+ 首次使用需要進行 OAuth2 認證,會開啟瀏覽器引導您完成授權流程。
51
+
52
+ ### 2. 查看狀態
53
+
54
+ ```bash
55
+ npx xero-cli-bin status
56
+ ```
57
+
58
+ ### 3. 查詢發票
59
+
60
+ ```bash
61
+ # 列出所有發票
62
+ npx xero-cli-bin invoices list
63
+
64
+ # 查詢已授權的應收發票
65
+ npx xero-cli-bin invoices list --type ACCREC --status AUTHORISED
66
+
67
+ # 條件查詢
68
+ npx xero-cli-bin invoices list --where "AmountDue>0"
69
+
70
+ # JSON 輸出
71
+ npx xero-cli-bin invoices list --json
72
+ ```
73
+
74
+ ### 4. 查詢聯絡人
75
+
76
+ ```bash
77
+ # 列出客戶
78
+ npx xero-cli-bin contacts list --type customer
79
+
80
+ # 搜尋聯絡人
81
+ npx xero-cli-bin contacts list --search-term "Smith"
82
+
83
+ # 條件查詢
84
+ npx xero-cli-bin contacts list --where "Name.Contains('ABC')"
85
+ ```
86
+
87
+ ### 5. 查詢帳戶
88
+
89
+ ```bash
90
+ npx xero-cli-bin accounts list
91
+ ```
92
+
93
+ ### 6. 查詢付款
94
+
95
+ ```bash
96
+ npx xero-cli-bin payments list --type AR
97
+ ```
98
+
99
+ ## 環境變數
100
+
101
+ | 變數 | 說明 | 必填 |
102
+ |------|------|------|
103
+ | `XERO_CLIENT_ID` | Xero Client ID | ✅ |
104
+ | `XERO_REDIRECT_URI` | Redirect URI | ❌ (預設:http://localhost:3456/callback) |
105
+ | `XERO_SCOPES` | OAuth Scopes | ❌ |
106
+
107
+ ## 常見命令
108
+
109
+ ```bash
110
+ # 認證
111
+ npx xero-cli-bin auth
112
+ npx xero-cli-bin auth --client-id=xxx --port=4000
113
+
114
+ # 狀態
115
+ npx xero-cli-bin status --json
116
+
117
+ # 發票
118
+ npx xero-cli-bin invoices list --type ACCREC --status AUTHORISED
119
+ npx xero-cli-bin invoices get <invoice-uuid>
120
+
121
+ # 聯絡人
122
+ npx xero-cli-bin contacts list --type customer
123
+ npx xero-cli-bin contacts get <contact-uuid>
124
+
125
+ # 帳戶
126
+ npx xero-cli-bin accounts list
127
+
128
+ # 付款
129
+ npx xero-cli-bin payments list --type AR
130
+
131
+ # 貸項通知單
132
+ npx xero-cli-bin creditnotes list
133
+
134
+ # Token 管理
135
+ npx xero-cli-bin refresh
136
+ npx xero-cli-bin revoke
137
+
138
+ # 說明
139
+ npx xero-cli-bin --help
140
+ npx xero-cli-bin --llms
141
+ ```
142
+
143
+ ## WHERE 子句語法
144
+
145
+ `--where` 參數接受 Xero API 的 SQL-like 查詢表達式:
146
+
147
+ ```bash
148
+ # 基本運算子
149
+ npx xero-cli-bin invoices list --where "AmountDue>1000"
150
+ npx xero-cli-bin invoices list --where "Status=\"AUTHORISED\""
151
+
152
+ # 日期查詢
153
+ npx xero-cli-bin invoices list --where "Date>=DateTime(2024, 01, 01)"
154
+
155
+ # GUID 查詢
156
+ npx xero-cli-bin contacts list --where "Contact.ContactID=Guid('123e4567-e89b-12d3-a456-426614174000')"
157
+
158
+ # 部分匹配
159
+ npx xero-cli-bin contacts list --where "Name.Contains('ABC')"
160
+ npx xero-cli-bin contacts list --where "Name.StartsWith('Smith')"
161
+
162
+ # 邏輯運算
163
+ npx xero-cli-bin invoices list --where "Type=\"ACCREC\" AND AmountDue>0"
164
+ npx xero-cli-bin invoices list --where "AmountDue>1000 OR Total>5000"
165
+ ```
166
+
167
+ ## 排序與分頁
168
+
169
+ ```bash
170
+ # 排序
171
+ npx xero-cli-bin invoices list --order-by Date --sort-direction DESC
172
+
173
+ # 分頁
174
+ npx xero-cli-bin invoices list --page 2 --page-size 50
175
+ ```
176
+
177
+ ## jq 整合
178
+
179
+ ```bash
180
+ # 統計總額
181
+ npx xero-cli-bin invoices list --json | jq '[.[].Total] | add'
182
+
183
+ # 依客戶分組
184
+ npx xero-cli-bin invoices list --json | \
185
+ jq 'group_by(.Contact.Name) | .[] | {name: .[0].Contact.Name, total: (map(.AmountDue) | add)}'
186
+
187
+ # 匯出 CSV
188
+ npx xero-cli-bin invoices list --json | \
189
+ jq -r '.[] | [.InvoiceNumber, .Contact.Name, .Total] | @csv'
190
+ ```
191
+
192
+ ## 安裝問題排除
193
+
194
+ ### 下載失敗
195
+
196
+ 如果安裝時下載失敗,請手動從 GitHub Releases 下載:
197
+
198
+ ```bash
199
+ # 前往 https://github.com/mmhk/xero-cli/releases
200
+ # 下載對應平台的壓縮檔
201
+ # 解壓後將二進制文件放到 PATH 中
202
+ ```
203
+
204
+ ### 權限問題(macOS/Linux)
205
+
206
+ ```bash
207
+ chmod +x $(npm root -g)/xero-cli-bin/bin/xero-cli
208
+ ```
209
+
210
+ ## 相關連結
211
+
212
+ - [GitHub Repository](https://github.com/mmhk/xero-cli)
213
+ - [Xero API 文件](https://developer.xero.com/documentation/)
214
+ - [CHANGELOG](https://github.com/mmhk/xero-cli/blob/main/CHANGELOG.md)
215
+ - [問題回報](https://github.com/mmhk/xero-cli/issues)
216
+
217
+ ## License
218
+
219
+ MIT License
package/bin/xero-cli ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const { join } = require('path');
5
+ const { platform } = process;
6
+
7
+ const ext = platform === 'win32' ? '.exe' : '';
8
+ const binaryPath = join(__dirname, `xero-cli${ext}`);
9
+
10
+ spawn(binaryPath, process.argv.slice(2), { stdio: 'inherit' })
11
+ .on('error', (err) => {
12
+ console.error('Failed to start xero-cli:', err.message);
13
+ process.exit(1);
14
+ })
15
+ .on('close', (code) => {
16
+ process.exit(code);
17
+ });
@@ -0,0 +1 @@
1
+ @node "%~dp0\xero-cli" %*
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "xero-cli-bin",
3
+ "version": "0.0.0",
4
+ "description": "Xero Accounting API CLI - Xero 會計 API 命令行工具",
5
+ "bin": {
6
+ "xero-cli": "./bin/xero-cli"
7
+ },
8
+ "scripts": {
9
+ "postinstall": "node ./scripts/install.js"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/mmhk/xero-cli.git"
14
+ },
15
+ "keywords": [
16
+ "xero",
17
+ "accounting",
18
+ "cli",
19
+ "xero-api",
20
+ "會計",
21
+ "發票",
22
+ "聯絡人"
23
+ ],
24
+ "author": "MMHK",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/mmhk/xero-cli/issues"
28
+ },
29
+ "homepage": "https://github.com/mmhk/xero-cli#readme",
30
+ "os": [
31
+ "win32",
32
+ "darwin",
33
+ "linux"
34
+ ],
35
+ "cpu": [
36
+ "x64",
37
+ "arm64"
38
+ ],
39
+ "engines": {
40
+ "node": ">=14.0.0"
41
+ }
42
+ }
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { platform, arch } = process;
4
+ const { join, dirname } = require('path');
5
+ const { execSync } = require('child_process');
6
+ const fs = require('fs');
7
+
8
+ const PLATFORM_MAP = {
9
+ win32: 'Windows',
10
+ darwin: 'Darwin',
11
+ linux: 'Linux'
12
+ };
13
+
14
+ const ARCH_MAP = {
15
+ x64: 'x86_64',
16
+ arm64: 'arm64'
17
+ };
18
+
19
+ function getBinaryName() {
20
+ const os = PLATFORM_MAP[platform];
21
+ const arch = ARCH_MAP[arch];
22
+ return `xero-cli_${os}_${arch}`;
23
+ }
24
+
25
+ function downloadFromGitHubRelease() {
26
+ const pkg = require('../package.json');
27
+ const version = pkg.version.replace(/^v/, '');
28
+ const binaryName = getBinaryName();
29
+ const ext = platform === 'win32' ? 'zip' : 'tar.gz';
30
+ const url = `https://github.com/mmhk/xero-cli/releases/download/v${version}/${binaryName}.${ext}`;
31
+
32
+ console.log(`[xero-cli-bin] Downloading from ${url}`);
33
+
34
+ const binDir = join(__dirname, '..');
35
+ const tarballPath = join(binDir, `download.${ext}`);
36
+
37
+ try {
38
+ execSync(`curl -L -o "${tarballPath}" "${url}"`, { stdio: 'inherit' });
39
+
40
+ console.log(`[xero-cli-bin] Extracting...`);
41
+ if (platform === 'win32') {
42
+ execSync(`powershell -Command "Expand-Archive -Path '${tarballPath}' -DestinationPath '${binDir}' -Force"`, { stdio: 'inherit' });
43
+ } else {
44
+ execSync(`tar -xf "${tarballPath}" -C "${binDir}"`, { stdio: 'inherit' });
45
+ }
46
+
47
+ fs.unlinkSync(tarballPath);
48
+
49
+ if (platform !== 'win32') {
50
+ const binaryPath = join(binDir, 'xero-cli');
51
+ fs.chmodSync(binaryPath, 0o755);
52
+ }
53
+
54
+ console.log('[xero-cli-bin] Installation complete!');
55
+ } catch (error) {
56
+ if (fs.existsSync(tarballPath)) {
57
+ fs.unlinkSync(tarballPath);
58
+ }
59
+ throw error;
60
+ }
61
+ }
62
+
63
+ console.log(`[xero-cli-bin] Platform: ${platform} ${arch}`);
64
+
65
+ try {
66
+ downloadFromGitHubRelease();
67
+ } catch (error) {
68
+ console.error('[xero-cli-bin] Installation failed:', error.message);
69
+ console.error('');
70
+ console.error('Please install manually from:');
71
+ console.error('https://github.com/mmhk/xero-cli/releases');
72
+ process.exit(1);
73
+ }