+1
-7
README.md
+1
-7
README.md
···
2
2
3
3
simple cli to fetch an anthropic access token using oauth (pkce), built with bun
4
4
5
-
## install
6
-
7
-
```bash
8
-
bun install
9
-
```
10
-
11
5
## usage
12
6
13
7
```bash
14
-
# only works via bunx since it uses bun libraries
15
8
bunx anthropic-api-key
9
+
npx anthropic-api-key
16
10
17
11
# override port
18
12
PORT=9999 bunx anthropic-api-key
+195
-2
bun.lock
+195
-2
bun.lock
···
3
3
"workspaces": {
4
4
"": {
5
5
"name": "anthropic-api-key",
6
+
"dependencies": {
7
+
"@types/express": "^5.0.3",
8
+
"express": "^5.1.0",
9
+
"net": "^1.0.2",
10
+
"node-fetch": "^3.3.2",
11
+
"open": "^10.2.0",
12
+
},
6
13
"devDependencies": {
7
14
"@types/bun": "latest",
8
-
},
9
-
"peerDependencies": {
10
15
"typescript": "^5",
11
16
},
12
17
},
13
18
},
14
19
"packages": {
20
+
"@types/body-parser": ["@types/body-parser@1.19.6", "", { "dependencies": { "@types/connect": "*", "@types/node": "*" } }, "sha512-HLFeCYgz89uk22N5Qg3dvGvsv46B8GLvKKo1zKG4NybA8U2DiEO3w9lqGg29t/tfLRJpJ6iQxnVw4OnB7MoM9g=="],
21
+
15
22
"@types/bun": ["@types/bun@1.2.19", "", { "dependencies": { "bun-types": "1.2.19" } }, "sha512-d9ZCmrH3CJ2uYKXQIUuZ/pUnTqIvLDS0SK7pFmbx8ma+ziH/FRMoAq5bYpRG7y+w1gl+HgyNZbtqgMq4W4e2Lg=="],
16
23
24
+
"@types/connect": ["@types/connect@3.4.38", "", { "dependencies": { "@types/node": "*" } }, "sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug=="],
25
+
26
+
"@types/express": ["@types/express@5.0.3", "", { "dependencies": { "@types/body-parser": "*", "@types/express-serve-static-core": "^5.0.0", "@types/serve-static": "*" } }, "sha512-wGA0NX93b19/dZC1J18tKWVIYWyyF2ZjT9vin/NRu0qzzvfVzWjs04iq2rQ3H65vCTQYlRqs3YHfY7zjdV+9Kw=="],
27
+
28
+
"@types/express-serve-static-core": ["@types/express-serve-static-core@5.0.7", "", { "dependencies": { "@types/node": "*", "@types/qs": "*", "@types/range-parser": "*", "@types/send": "*" } }, "sha512-R+33OsgWw7rOhD1emjU7dzCDHucJrgJXMA5PYCzJxVil0dsyx5iBEPHqpPfiKNJQb7lZ1vxwoLR4Z87bBUpeGQ=="],
29
+
30
+
"@types/http-errors": ["@types/http-errors@2.0.5", "", {}, "sha512-r8Tayk8HJnX0FztbZN7oVqGccWgw98T/0neJphO91KkmOzug1KkofZURD4UaD5uH8AqcFLfdPErnBod0u71/qg=="],
31
+
32
+
"@types/mime": ["@types/mime@1.3.5", "", {}, "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w=="],
33
+
17
34
"@types/node": ["@types/node@24.1.0", "", { "dependencies": { "undici-types": "~7.8.0" } }, "sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w=="],
35
+
36
+
"@types/qs": ["@types/qs@6.14.0", "", {}, "sha512-eOunJqu0K1923aExK6y8p6fsihYEn/BYuQ4g0CxAAgFc4b/ZLN4CrsRZ55srTdqoiLzU2B2evC+apEIxprEzkQ=="],
37
+
38
+
"@types/range-parser": ["@types/range-parser@1.2.7", "", {}, "sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ=="],
18
39
19
40
"@types/react": ["@types/react@19.1.9", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-WmdoynAX8Stew/36uTSVMcLJJ1KRh6L3IZRx1PZ7qJtBqT3dYTgyDTx8H1qoRghErydW7xw9mSJ3wS//tCRpFA=="],
20
41
42
+
"@types/send": ["@types/send@0.17.5", "", { "dependencies": { "@types/mime": "^1", "@types/node": "*" } }, "sha512-z6F2D3cOStZvuk2SaP6YrwkNO65iTZcwA2ZkSABegdkAh/lf+Aa/YQndZVfmEXT5vgAp6zv06VQ3ejSVjAny4w=="],
43
+
44
+
"@types/serve-static": ["@types/serve-static@1.15.8", "", { "dependencies": { "@types/http-errors": "*", "@types/node": "*", "@types/send": "*" } }, "sha512-roei0UY3LhpOJvjbIP6ZZFngyLKl5dskOtDhxY5THRSpO+ZI+nzJ+m5yUMzGrp89YRa7lvknKkMYjqQFGwA7Sg=="],
45
+
46
+
"accepts": ["accepts@2.0.0", "", { "dependencies": { "mime-types": "^3.0.0", "negotiator": "^1.0.0" } }, "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng=="],
47
+
48
+
"body-parser": ["body-parser@2.2.0", "", { "dependencies": { "bytes": "^3.1.2", "content-type": "^1.0.5", "debug": "^4.4.0", "http-errors": "^2.0.0", "iconv-lite": "^0.6.3", "on-finished": "^2.4.1", "qs": "^6.14.0", "raw-body": "^3.0.0", "type-is": "^2.0.0" } }, "sha512-02qvAaxv8tp7fBa/mw1ga98OGm+eCbqzJOKoRt70sLmfEEi+jyBYVTDGfCL/k06/4EMk/z01gCe7HoCH/f2LTg=="],
49
+
21
50
"bun-types": ["bun-types@1.2.19", "", { "dependencies": { "@types/node": "*" }, "peerDependencies": { "@types/react": "^19" } }, "sha512-uAOTaZSPuYsWIXRpj7o56Let0g/wjihKCkeRqUBhlLVM/Bt+Fj9xTo+LhC1OV1XDaGkz4hNC80et5xgy+9KTHQ=="],
22
51
52
+
"bundle-name": ["bundle-name@4.1.0", "", { "dependencies": { "run-applescript": "^7.0.0" } }, "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q=="],
53
+
54
+
"bytes": ["bytes@3.1.2", "", {}, "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="],
55
+
56
+
"call-bind-apply-helpers": ["call-bind-apply-helpers@1.0.2", "", { "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2" } }, "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ=="],
57
+
58
+
"call-bound": ["call-bound@1.0.4", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "get-intrinsic": "^1.3.0" } }, "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg=="],
59
+
60
+
"content-disposition": ["content-disposition@1.0.0", "", { "dependencies": { "safe-buffer": "5.2.1" } }, "sha512-Au9nRL8VNUut/XSzbQA38+M78dzP4D+eqg3gfJHMIHHYa3bg067xj1KxMUWj+VULbiZMowKngFFbKczUrNJ1mg=="],
61
+
62
+
"content-type": ["content-type@1.0.5", "", {}, "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA=="],
63
+
64
+
"cookie": ["cookie@0.7.2", "", {}, "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w=="],
65
+
66
+
"cookie-signature": ["cookie-signature@1.2.2", "", {}, "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg=="],
67
+
23
68
"csstype": ["csstype@3.1.3", "", {}, "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw=="],
24
69
70
+
"data-uri-to-buffer": ["data-uri-to-buffer@4.0.1", "", {}, "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A=="],
71
+
72
+
"debug": ["debug@4.4.1", "", { "dependencies": { "ms": "^2.1.3" } }, "sha512-KcKCqiftBJcZr++7ykoDIEwSa3XWowTfNPo92BYxjXiyYEVrUQh2aLyhxBCwww+heortUFxEJYcRzosstTEBYQ=="],
73
+
74
+
"default-browser": ["default-browser@5.2.1", "", { "dependencies": { "bundle-name": "^4.1.0", "default-browser-id": "^5.0.0" } }, "sha512-WY/3TUME0x3KPYdRRxEJJvXRHV4PyPoUsxtZa78lwItwRQRHhd2U9xOscaT/YTf8uCXIAjeJOFBVEh/7FtD8Xg=="],
75
+
76
+
"default-browser-id": ["default-browser-id@5.0.0", "", {}, "sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA=="],
77
+
78
+
"define-lazy-prop": ["define-lazy-prop@3.0.0", "", {}, "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg=="],
79
+
80
+
"depd": ["depd@2.0.0", "", {}, "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw=="],
81
+
82
+
"dunder-proto": ["dunder-proto@1.0.1", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.1", "es-errors": "^1.3.0", "gopd": "^1.2.0" } }, "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A=="],
83
+
84
+
"ee-first": ["ee-first@1.1.1", "", {}, "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow=="],
85
+
86
+
"encodeurl": ["encodeurl@2.0.0", "", {}, "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg=="],
87
+
88
+
"es-define-property": ["es-define-property@1.0.1", "", {}, "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g=="],
89
+
90
+
"es-errors": ["es-errors@1.3.0", "", {}, "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw=="],
91
+
92
+
"es-object-atoms": ["es-object-atoms@1.1.1", "", { "dependencies": { "es-errors": "^1.3.0" } }, "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA=="],
93
+
94
+
"escape-html": ["escape-html@1.0.3", "", {}, "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="],
95
+
96
+
"etag": ["etag@1.8.1", "", {}, "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg=="],
97
+
98
+
"express": ["express@5.1.0", "", { "dependencies": { "accepts": "^2.0.0", "body-parser": "^2.2.0", "content-disposition": "^1.0.0", "content-type": "^1.0.5", "cookie": "^0.7.1", "cookie-signature": "^1.2.1", "debug": "^4.4.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "finalhandler": "^2.1.0", "fresh": "^2.0.0", "http-errors": "^2.0.0", "merge-descriptors": "^2.0.0", "mime-types": "^3.0.0", "on-finished": "^2.4.1", "once": "^1.4.0", "parseurl": "^1.3.3", "proxy-addr": "^2.0.7", "qs": "^6.14.0", "range-parser": "^1.2.1", "router": "^2.2.0", "send": "^1.1.0", "serve-static": "^2.2.0", "statuses": "^2.0.1", "type-is": "^2.0.1", "vary": "^1.1.2" } }, "sha512-DT9ck5YIRU+8GYzzU5kT3eHGA5iL+1Zd0EutOmTE9Dtk+Tvuzd23VBU+ec7HPNSTxXYO55gPV/hq4pSBJDjFpA=="],
99
+
100
+
"fetch-blob": ["fetch-blob@3.2.0", "", { "dependencies": { "node-domexception": "^1.0.0", "web-streams-polyfill": "^3.0.3" } }, "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ=="],
101
+
102
+
"finalhandler": ["finalhandler@2.1.0", "", { "dependencies": { "debug": "^4.4.0", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "on-finished": "^2.4.1", "parseurl": "^1.3.3", "statuses": "^2.0.1" } }, "sha512-/t88Ty3d5JWQbWYgaOGCCYfXRwV1+be02WqYYlL6h0lEiUAMPM8o8qKGO01YIkOHzka2up08wvgYD0mDiI+q3Q=="],
103
+
104
+
"formdata-polyfill": ["formdata-polyfill@4.0.10", "", { "dependencies": { "fetch-blob": "^3.1.2" } }, "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g=="],
105
+
106
+
"forwarded": ["forwarded@0.2.0", "", {}, "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow=="],
107
+
108
+
"fresh": ["fresh@2.0.0", "", {}, "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A=="],
109
+
110
+
"function-bind": ["function-bind@1.1.2", "", {}, "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="],
111
+
112
+
"get-intrinsic": ["get-intrinsic@1.3.0", "", { "dependencies": { "call-bind-apply-helpers": "^1.0.2", "es-define-property": "^1.0.1", "es-errors": "^1.3.0", "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", "get-proto": "^1.0.1", "gopd": "^1.2.0", "has-symbols": "^1.1.0", "hasown": "^2.0.2", "math-intrinsics": "^1.1.0" } }, "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ=="],
113
+
114
+
"get-proto": ["get-proto@1.0.1", "", { "dependencies": { "dunder-proto": "^1.0.1", "es-object-atoms": "^1.0.0" } }, "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g=="],
115
+
116
+
"gopd": ["gopd@1.2.0", "", {}, "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg=="],
117
+
118
+
"has-symbols": ["has-symbols@1.1.0", "", {}, "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ=="],
119
+
120
+
"hasown": ["hasown@2.0.2", "", { "dependencies": { "function-bind": "^1.1.2" } }, "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ=="],
121
+
122
+
"http-errors": ["http-errors@2.0.0", "", { "dependencies": { "depd": "2.0.0", "inherits": "2.0.4", "setprototypeof": "1.2.0", "statuses": "2.0.1", "toidentifier": "1.0.1" } }, "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ=="],
123
+
124
+
"iconv-lite": ["iconv-lite@0.6.3", "", { "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" } }, "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw=="],
125
+
126
+
"inherits": ["inherits@2.0.4", "", {}, "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="],
127
+
128
+
"ipaddr.js": ["ipaddr.js@1.9.1", "", {}, "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g=="],
129
+
130
+
"is-docker": ["is-docker@3.0.0", "", { "bin": { "is-docker": "cli.js" } }, "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ=="],
131
+
132
+
"is-inside-container": ["is-inside-container@1.0.0", "", { "dependencies": { "is-docker": "^3.0.0" }, "bin": { "is-inside-container": "cli.js" } }, "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA=="],
133
+
134
+
"is-promise": ["is-promise@4.0.0", "", {}, "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="],
135
+
136
+
"is-wsl": ["is-wsl@3.1.0", "", { "dependencies": { "is-inside-container": "^1.0.0" } }, "sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw=="],
137
+
138
+
"math-intrinsics": ["math-intrinsics@1.1.0", "", {}, "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="],
139
+
140
+
"media-typer": ["media-typer@1.1.0", "", {}, "sha512-aisnrDP4GNe06UcKFnV5bfMNPBUw4jsLGaWwWfnH3v02GnBuXX2MCVn5RbrWo0j3pczUilYblq7fQ7Nw2t5XKw=="],
141
+
142
+
"merge-descriptors": ["merge-descriptors@2.0.0", "", {}, "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g=="],
143
+
144
+
"mime-db": ["mime-db@1.54.0", "", {}, "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ=="],
145
+
146
+
"mime-types": ["mime-types@3.0.1", "", { "dependencies": { "mime-db": "^1.54.0" } }, "sha512-xRc4oEhT6eaBpU1XF7AjpOFD+xQmXNB5OVKwp4tqCuBpHLS/ZbBDrc07mYTDqVMg6PfxUjjNp85O6Cd2Z/5HWA=="],
147
+
148
+
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
149
+
150
+
"negotiator": ["negotiator@1.0.0", "", {}, "sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg=="],
151
+
152
+
"net": ["net@1.0.2", "", {}, "sha512-kbhcj2SVVR4caaVnGLJKmlk2+f+oLkjqdKeQlmUtz6nGzOpbcobwVIeSURNgraV/v3tlmGIX82OcPCl0K6RbHQ=="],
153
+
154
+
"node-domexception": ["node-domexception@1.0.0", "", {}, "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ=="],
155
+
156
+
"node-fetch": ["node-fetch@3.3.2", "", { "dependencies": { "data-uri-to-buffer": "^4.0.0", "fetch-blob": "^3.1.4", "formdata-polyfill": "^4.0.10" } }, "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA=="],
157
+
158
+
"object-inspect": ["object-inspect@1.13.4", "", {}, "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew=="],
159
+
160
+
"on-finished": ["on-finished@2.4.1", "", { "dependencies": { "ee-first": "1.1.1" } }, "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg=="],
161
+
162
+
"once": ["once@1.4.0", "", { "dependencies": { "wrappy": "1" } }, "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w=="],
163
+
164
+
"open": ["open@10.2.0", "", { "dependencies": { "default-browser": "^5.2.1", "define-lazy-prop": "^3.0.0", "is-inside-container": "^1.0.0", "wsl-utils": "^0.1.0" } }, "sha512-YgBpdJHPyQ2UE5x+hlSXcnejzAvD0b22U2OuAP+8OnlJT+PjWPxtgmGqKKc+RgTM63U9gN0YzrYc71R2WT/hTA=="],
165
+
166
+
"parseurl": ["parseurl@1.3.3", "", {}, "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="],
167
+
168
+
"path-to-regexp": ["path-to-regexp@8.2.0", "", {}, "sha512-TdrF7fW9Rphjq4RjrW0Kp2AW0Ahwu9sRGTkS6bvDi0SCwZlEZYmcfDbEsTz8RVk0EHIS/Vd1bv3JhG+1xZuAyQ=="],
169
+
170
+
"proxy-addr": ["proxy-addr@2.0.7", "", { "dependencies": { "forwarded": "0.2.0", "ipaddr.js": "1.9.1" } }, "sha512-llQsMLSUDUPT44jdrU/O37qlnifitDP+ZwrmmZcoSKyLKvtZxpyV0n2/bD/N4tBAAZ/gJEdZU7KMraoK1+XYAg=="],
171
+
172
+
"qs": ["qs@6.14.0", "", { "dependencies": { "side-channel": "^1.1.0" } }, "sha512-YWWTjgABSKcvs/nWBi9PycY/JiPJqOD4JA6o9Sej2AtvSGarXxKC3OQSk4pAarbdQlKAh5D4FCQkJNkW+GAn3w=="],
173
+
174
+
"range-parser": ["range-parser@1.2.1", "", {}, "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="],
175
+
176
+
"raw-body": ["raw-body@3.0.0", "", { "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", "iconv-lite": "0.6.3", "unpipe": "1.0.0" } }, "sha512-RmkhL8CAyCRPXCE28MMH0z2PNWQBNk2Q09ZdxM9IOOXwxwZbN+qbWaatPkdkWIKL2ZVDImrN/pK5HTRz2PcS4g=="],
177
+
178
+
"router": ["router@2.2.0", "", { "dependencies": { "debug": "^4.4.0", "depd": "^2.0.0", "is-promise": "^4.0.0", "parseurl": "^1.3.3", "path-to-regexp": "^8.0.0" } }, "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ=="],
179
+
180
+
"run-applescript": ["run-applescript@7.0.0", "", {}, "sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A=="],
181
+
182
+
"safe-buffer": ["safe-buffer@5.2.1", "", {}, "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="],
183
+
184
+
"safer-buffer": ["safer-buffer@2.1.2", "", {}, "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="],
185
+
186
+
"send": ["send@1.2.0", "", { "dependencies": { "debug": "^4.3.5", "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "etag": "^1.8.1", "fresh": "^2.0.0", "http-errors": "^2.0.0", "mime-types": "^3.0.1", "ms": "^2.1.3", "on-finished": "^2.4.1", "range-parser": "^1.2.1", "statuses": "^2.0.1" } }, "sha512-uaW0WwXKpL9blXE2o0bRhoL2EGXIrZxQ2ZQ4mgcfoBxdFmQold+qWsD2jLrfZ0trjKL6vOw0j//eAwcALFjKSw=="],
187
+
188
+
"serve-static": ["serve-static@2.2.0", "", { "dependencies": { "encodeurl": "^2.0.0", "escape-html": "^1.0.3", "parseurl": "^1.3.3", "send": "^1.2.0" } }, "sha512-61g9pCh0Vnh7IutZjtLGGpTA355+OPn2TyDv/6ivP2h/AdAVX9azsoxmg2/M6nZeQZNYBEwIcsne1mJd9oQItQ=="],
189
+
190
+
"setprototypeof": ["setprototypeof@1.2.0", "", {}, "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="],
191
+
192
+
"side-channel": ["side-channel@1.1.0", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3", "side-channel-list": "^1.0.0", "side-channel-map": "^1.0.1", "side-channel-weakmap": "^1.0.2" } }, "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw=="],
193
+
194
+
"side-channel-list": ["side-channel-list@1.0.0", "", { "dependencies": { "es-errors": "^1.3.0", "object-inspect": "^1.13.3" } }, "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA=="],
195
+
196
+
"side-channel-map": ["side-channel-map@1.0.1", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3" } }, "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA=="],
197
+
198
+
"side-channel-weakmap": ["side-channel-weakmap@1.0.2", "", { "dependencies": { "call-bound": "^1.0.2", "es-errors": "^1.3.0", "get-intrinsic": "^1.2.5", "object-inspect": "^1.13.3", "side-channel-map": "^1.0.1" } }, "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A=="],
199
+
200
+
"statuses": ["statuses@2.0.2", "", {}, "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw=="],
201
+
202
+
"toidentifier": ["toidentifier@1.0.1", "", {}, "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="],
203
+
204
+
"type-is": ["type-is@2.0.1", "", { "dependencies": { "content-type": "^1.0.5", "media-typer": "^1.1.0", "mime-types": "^3.0.0" } }, "sha512-OZs6gsjF4vMp32qrCbiVSkrFmXtG/AZhY3t0iAMrMBiAZyV9oALtXO8hsrHbMXF9x6L3grlFuwW2oAz7cav+Gw=="],
205
+
25
206
"typescript": ["typescript@5.9.2", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-CWBzXQrc/qOkhidw1OzBTQuYRbfyxDXJMVJ1XNwUHGROVmuaeiEm3OslpZ1RV96d7SKKjZKrSJu3+t/xlw3R9A=="],
26
207
27
208
"undici-types": ["undici-types@7.8.0", "", {}, "sha512-9UJ2xGDvQ43tYyVMpuHlsgApydB8ZKfVYTsLDhXkFL/6gfkp+U8xTGdh8pMJv1SpZna0zxG1DwsKZsreLbXBxw=="],
209
+
210
+
"unpipe": ["unpipe@1.0.0", "", {}, "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ=="],
211
+
212
+
"vary": ["vary@1.1.2", "", {}, "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg=="],
213
+
214
+
"web-streams-polyfill": ["web-streams-polyfill@3.3.3", "", {}, "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw=="],
215
+
216
+
"wrappy": ["wrappy@1.0.2", "", {}, "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="],
217
+
218
+
"wsl-utils": ["wsl-utils@0.1.0", "", { "dependencies": { "is-wsl": "^3.1.0" } }, "sha512-h3Fbisa2nKGPxCpm89Hk33lBLsnaGBvctQopaBSOW/uIs6FTe1ATyAnKFJrzVs9vpGdsTe73WF3V4lIsk4Gacw=="],
219
+
220
+
"http-errors/statuses": ["statuses@2.0.1", "", {}, "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ=="],
28
221
}
29
222
}
+7
-1
package.json
+7
-1
package.json
···
1
1
{
2
2
"name": "anthropic-api-key",
3
-
"version": "0.1.8",
3
+
"version": "0.2.1",
4
4
"description": "CLI to fetch Anthropic API access tokens via OAuth with PKCE using Bun.",
5
5
"type": "module",
6
6
"private": false,
···
32
32
"devDependencies": {
33
33
"@types/bun": "latest",
34
34
"typescript": "^5"
35
+
},
36
+
"dependencies": {
37
+
"@types/express": "^5.0.3",
38
+
"express": "^5.1.0",
39
+
"node-fetch": "^3.3.2",
40
+
"open": "^10.2.0"
35
41
}
36
42
}
+76
-115
src/index.ts
+76
-115
src/index.ts
···
1
-
#!/usr/bin/env bun
2
-
3
-
// Detect if running under Node.js instead of Bun
4
-
if (typeof Bun === "undefined") {
5
-
console.error(
6
-
"❌ This CLI requires Bun. Please install Bun from https://bun.sh/",
7
-
);
8
-
process.exit(1);
9
-
}
1
+
#!/usr/bin/env node
10
2
11
-
import { serve } from "bun";
3
+
import { createServer } from "node:http";
4
+
import express from "express";
5
+
import fetch from "node-fetch";
6
+
import open from "open";
12
7
import {
13
8
bootstrapFromDisk,
14
9
exchangeRefreshToken,
···
16
11
saveToDisk,
17
12
} from "./lib/token";
18
13
19
-
const PORT = Number(Bun.env.PORT || 8787);
14
+
const PORT = Number(process.env.PORT || 8787);
20
15
21
-
function json(data: unknown, init: ResponseInit = {}) {
22
-
return new Response(JSON.stringify(data), {
23
-
headers: { "content-type": "application/json", ...(init.headers || {}) },
24
-
...init,
25
-
});
16
+
function json(res: express.Response, data: unknown, status = 200) {
17
+
res.status(status).json(data);
26
18
}
27
19
28
20
const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
···
81
73
client_id: CLIENT_ID,
82
74
redirect_uri: "https://console.anthropic.com/oauth/code/callback",
83
75
code_verifier: verifier,
84
-
} satisfies Record<string, string>;
76
+
} as Record<string, string>;
85
77
const res = await fetch("https://console.anthropic.com/v1/oauth/token", {
86
78
method: "POST",
87
79
headers: {
···
103
95
104
96
const argv = process.argv.slice(2);
105
97
if (argv.includes("-h") || argv.includes("--help")) {
106
-
Bun.write(Bun.stdout, `Usage: anthropic\n\n`);
107
-
Bun.write(
108
-
Bun.stdout,
109
-
` anthropic Start UI and flow; prints token on success and exits.\n`,
98
+
console.log(`Usage: anthropic\n`);
99
+
console.log(
100
+
` anthropic Start UI and flow; prints token on success and exits.`,
110
101
);
111
-
Bun.write(
112
-
Bun.stdout,
113
-
` PORT=xxxx anthropic Override port (default 8787).\n`,
114
-
);
115
-
Bun.write(
116
-
Bun.stdout,
102
+
console.log(` PORT=xxxx anthropic Override port (default 8787).`);
103
+
console.log(
117
104
`\nTokens are cached at ~/.config/crush/anthropic and reused on later runs.\n`,
118
105
);
119
106
process.exit(0);
···
309
296
string,
310
297
{ accessToken: string; refreshToken: string; expiresAt: number }
311
298
>();
312
-
serve({
313
-
port: PORT,
314
-
development: { console: false },
315
-
routes: {
316
-
"/api/auth/start": {
317
-
POST: async () => {
318
-
const { verifier, challenge } = await pkcePair();
319
-
const authUrl = authorizeUrl(verifier, challenge);
320
-
return json({ authUrl, verifier });
321
-
},
322
-
},
299
+
const app = express();
300
+
app.use(express.json());
323
301
324
-
"/api/auth/complete": {
325
-
POST: async (req) => {
326
-
const body = (await req.json().catch(() => ({}))) as {
327
-
code?: string;
328
-
verifier?: string;
329
-
};
330
-
const code = String(body.code ?? "");
331
-
const verifier = String(body.verifier ?? "");
332
-
if (!code || !verifier)
333
-
return json({ error: "missing code or verifier" }, { status: 400 });
334
-
const tokens = await exchangeAuthorizationCode(code, verifier);
335
-
const expiresAt =
336
-
Math.floor(Date.now() / 1000) + (tokens.expires_in ?? 0);
337
-
const entry = {
338
-
accessToken: tokens.access_token,
339
-
refreshToken: tokens.refresh_token,
340
-
expiresAt,
341
-
};
342
-
memory.set("tokens", entry);
343
-
await saveToDisk(entry);
344
-
Bun.write(Bun.stdout, `${entry.accessToken}\n`);
345
-
setTimeout(() => process.exit(0), 100);
346
-
return json({ ok: true });
347
-
},
348
-
},
302
+
app.post("/api/auth/start", async (_req, res) => {
303
+
const { verifier, challenge } = await pkcePair();
304
+
const authUrl = authorizeUrl(verifier, challenge);
305
+
json(res, { authUrl, verifier });
306
+
});
307
+
308
+
app.post("/api/auth/complete", async (req, res) => {
309
+
const body = req.body as { code?: string; verifier?: string };
310
+
const code = String(body.code ?? "");
311
+
const verifier = String(body.verifier ?? "");
312
+
if (!code || !verifier)
313
+
return json(res, { error: "missing code or verifier" }, 400);
314
+
const tokens = await exchangeAuthorizationCode(code, verifier);
315
+
const expiresAt = Math.floor(Date.now() / 1000) + (tokens.expires_in ?? 0);
316
+
const entry = {
317
+
accessToken: tokens.access_token,
318
+
refreshToken: tokens.refresh_token,
319
+
expiresAt,
320
+
};
321
+
memory.set("tokens", entry);
322
+
await saveToDisk(entry);
323
+
console.log(`${entry.accessToken}\n`);
324
+
setTimeout(() => process.exit(0), 100);
325
+
json(res, { ok: true });
326
+
});
349
327
350
-
// Get current token (refresh if needed)
351
-
"/api/token": {
352
-
GET: async () => {
353
-
let entry = memory.get("tokens");
354
-
if (!entry) {
355
-
const disk = await loadFromDisk();
356
-
if (disk) {
357
-
entry = disk;
358
-
memory.set("tokens", entry);
359
-
}
360
-
}
361
-
if (!entry)
362
-
return json({ error: "not_authenticated" }, { status: 401 });
363
-
const now = Math.floor(Date.now() / 1000);
364
-
if (now >= entry.expiresAt - 60) {
365
-
const refreshed = await exchangeRefreshToken(entry.refreshToken);
366
-
entry.accessToken = refreshed.access_token;
367
-
entry.expiresAt =
368
-
Math.floor(Date.now() / 1000) + refreshed.expires_in;
369
-
if (refreshed.refresh_token)
370
-
entry.refreshToken = refreshed.refresh_token;
371
-
memory.set("tokens", entry);
372
-
await saveToDisk(entry);
373
-
}
374
-
return json({
375
-
accessToken: entry.accessToken,
376
-
expiresAt: entry.expiresAt,
377
-
});
378
-
},
379
-
},
328
+
app.get("/api/token", async (_req, res) => {
329
+
let entry = memory.get("tokens");
330
+
if (!entry) {
331
+
const disk = await loadFromDisk();
332
+
if (disk) {
333
+
entry = disk;
334
+
memory.set("tokens", entry);
335
+
}
336
+
}
337
+
if (!entry) return json(res, { error: "not_authenticated" }, 401);
338
+
const now = Math.floor(Date.now() / 1000);
339
+
if (now >= entry.expiresAt - 60) {
340
+
const refreshed = await exchangeRefreshToken(entry.refreshToken);
341
+
entry.accessToken = refreshed.access_token;
342
+
entry.expiresAt = Math.floor(Date.now() / 1000) + refreshed.expires_in;
343
+
if (refreshed.refresh_token) entry.refreshToken = refreshed.refresh_token;
344
+
memory.set("tokens", entry);
345
+
await saveToDisk(entry);
346
+
}
347
+
json(res, {
348
+
accessToken: entry.accessToken,
349
+
expiresAt: entry.expiresAt,
350
+
});
351
+
});
380
352
381
-
// Wildcard route for all other /api/ routes
382
-
"/": () =>
383
-
new Response(indexHtml, {
384
-
headers: { "content-type": "text/html; charset=utf-8" },
385
-
}),
386
-
},
353
+
app.get("/", (_req, res) => {
354
+
res.setHeader("content-type", "text/html; charset=utf-8");
355
+
res.send(indexHtml);
356
+
});
387
357
388
-
// Fallback for all other routes: serve static or 404
389
-
fetch() {
390
-
return new Response(
391
-
"something went wrong and your request fell through",
392
-
{ status: 404 },
393
-
);
394
-
},
358
+
app.use((_req, res) => {
359
+
res.status(404).send("something went wrong and your request fell through");
395
360
});
396
361
397
-
// Open browser
398
-
const url = `http://localhost:${PORT}`;
399
-
if (process.platform === "darwin") {
400
-
Bun.$`open ${url}`.catch(() => {});
401
-
} else if (process.platform === "win32") {
402
-
Bun.$`cmd /c start "" ${url}`.catch(() => {});
403
-
} else {
404
-
Bun.$`xdg-open ${url}`.catch(() => {});
405
-
}
362
+
const server = createServer(app);
363
+
server.listen(PORT, async () => {
364
+
const url = `http://localhost:${PORT}`;
365
+
await open(url);
366
+
});
406
367
}
+18
-15
src/lib/token.ts
+18
-15
src/lib/token.ts
···
1
+
import { chmodSync, existsSync } from "node:fs";
2
+
import fs from "node:fs/promises";
3
+
import path from "node:path";
4
+
1
5
const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e";
2
6
3
-
const HOME = Bun.env.HOME || Bun.env.USERPROFILE || ".";
4
-
const CACHE_DIR = `${HOME}/.config/crush/anthropic`;
5
-
const BEARER_FILE = `${CACHE_DIR}/bearer_token`;
6
-
const REFRESH_FILE = `${CACHE_DIR}/refresh_token`;
7
-
const EXPIRES_FILE = `${CACHE_DIR}/bearer_token.expires`;
7
+
const HOME = process.env.HOME || process.env.USERPROFILE || ".";
8
+
const CACHE_DIR = path.join(HOME, ".config/crush/anthropic");
9
+
const BEARER_FILE = path.join(CACHE_DIR, "bearer_token");
10
+
const REFRESH_FILE = path.join(CACHE_DIR, "refresh_token");
11
+
const EXPIRES_FILE = path.join(CACHE_DIR, "bearer_token.expires");
8
12
9
13
export type TokenEntry = {
10
14
accessToken: string;
···
13
17
};
14
18
15
19
export async function ensureDir() {
16
-
await Bun.$`mkdir -p ${CACHE_DIR}`;
20
+
await fs.mkdir(CACHE_DIR, { recursive: true });
17
21
}
18
22
19
-
export async function writeSecret(path: string, data: string) {
20
-
await Bun.write(path, data);
21
-
await Bun.$`chmod 600 ${path}`;
23
+
export async function writeSecret(filePath: string, data: string) {
24
+
await fs.writeFile(filePath, data, { encoding: "utf8", mode: 0o600 });
25
+
chmodSync(filePath, 0o600);
22
26
}
23
27
24
-
export async function readText(path: string) {
25
-
const f = Bun.file(path);
26
-
if (!(await f.exists())) return undefined;
27
-
return await f.text();
28
+
export async function readText(filePath: string) {
29
+
if (!existsSync(filePath)) return undefined;
30
+
return await fs.readFile(filePath, "utf8");
28
31
}
29
32
30
33
export async function loadFromDisk(): Promise<TokenEntry | undefined> {
···
79
82
if (!entry) return false;
80
83
const now = Math.floor(Date.now() / 1000);
81
84
if (now < entry.expiresAt - 60) {
82
-
Bun.write(Bun.stdout, `${entry.accessToken}\n`);
85
+
process.stdout.write(`${entry.accessToken}\n`);
83
86
setTimeout(() => process.exit(0), 50);
84
87
return true;
85
88
}
···
89
92
entry.expiresAt = Math.floor(Date.now() / 1000) + refreshed.expires_in;
90
93
if (refreshed.refresh_token) entry.refreshToken = refreshed.refresh_token;
91
94
await saveToDisk(entry);
92
-
Bun.write(Bun.stdout, `${entry.accessToken}\n`);
95
+
process.stdout.write(`${entry.accessToken}\n`);
93
96
setTimeout(() => process.exit(0), 50);
94
97
return true;
95
98
} catch {