@omnicross/subscriptions 0.3.0 → 0.4.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.
@@ -1,394 +0,0 @@
1
- import {
2
- __export
3
- } from "./chunk-MLKGABMK.js";
4
-
5
- // src/oauth/flows/claude.ts
6
- var claude_exports = {};
7
- __export(claude_exports, {
8
- exchangeCodeForTokens: () => exchangeCodeForTokens,
9
- exchangeSetupTokenCode: () => exchangeSetupTokenCode,
10
- generateAuthParams: () => generateAuthParams,
11
- generateSetupTokenParams: () => generateSetupTokenParams,
12
- refreshAccessToken: () => refreshAccessToken
13
- });
14
- import crypto from "crypto";
15
-
16
- // src/oauth/fetchPort.ts
17
- function errorMessage(error, errorDescription) {
18
- if (errorDescription) return errorDescription;
19
- if (typeof error === "string") return error;
20
- if (error && typeof error === "object") {
21
- const e = error;
22
- if (typeof e.message === "string" && e.message) return e.message;
23
- if (typeof e.error_description === "string" && e.error_description) {
24
- return e.error_description;
25
- }
26
- return JSON.stringify(error);
27
- }
28
- return String(error);
29
- }
30
- function withStatus(message, response) {
31
- return response.ok ? message : `${message} (HTTP ${response.status})`;
32
- }
33
- var DEFAULT_TOKEN_TIMEOUT_MS = 3e4;
34
- async function fetchWithTimeout(fetchImpl, url, init, timeoutMs) {
35
- const controller = new AbortController();
36
- const timer = setTimeout(() => controller.abort(), timeoutMs);
37
- try {
38
- return await fetchImpl(url, { ...init, signal: controller.signal });
39
- } catch (e) {
40
- if (controller.signal.aborted) {
41
- throw new Error(`token endpoint timed out after ${Math.round(timeoutMs / 1e3)}s`);
42
- }
43
- throw e;
44
- } finally {
45
- clearTimeout(timer);
46
- }
47
- }
48
- async function postForm(fetchImpl, url, params, parseErrorMessage, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
49
- const response = await fetchWithTimeout(
50
- fetchImpl,
51
- url,
52
- {
53
- method: "POST",
54
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
55
- body: params.toString()
56
- },
57
- timeoutMs
58
- );
59
- const responseData = await response.text();
60
- let data;
61
- try {
62
- data = JSON.parse(responseData);
63
- } catch {
64
- throw new Error(withStatus(parseErrorMessage, response));
65
- }
66
- if (data.error) {
67
- throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
68
- }
69
- return data;
70
- }
71
- async function postJson(fetchImpl, url, body, parseErrorMessage, extraHeaders = {}, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
72
- const response = await fetchWithTimeout(
73
- fetchImpl,
74
- url,
75
- {
76
- method: "POST",
77
- headers: { "Content-Type": "application/json", ...extraHeaders },
78
- body: JSON.stringify(body)
79
- },
80
- timeoutMs
81
- );
82
- const responseData = await response.text();
83
- let data;
84
- try {
85
- data = JSON.parse(responseData);
86
- } catch {
87
- throw new Error(withStatus(parseErrorMessage, response));
88
- }
89
- if (data.error) {
90
- throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
91
- }
92
- if (!response.ok) {
93
- throw new Error(withStatus("token endpoint rejected the request", response));
94
- }
95
- return data;
96
- }
97
-
98
- // src/oauth/flows/claude.ts
99
- var CLAUDE_TOKEN_HEADERS = {
100
- "User-Agent": "claude-cli/1.0.56 (external, cli)",
101
- Accept: "application/json, text/plain, */*",
102
- "Accept-Language": "en-US,en;q=0.9",
103
- Referer: "https://claude.ai/",
104
- Origin: "https://claude.ai"
105
- };
106
- var CLAUDE_OAUTH_CONFIG = {
107
- clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
108
- authorizationEndpoint: "https://claude.ai/oauth/authorize",
109
- // The token endpoint moved to platform.claude.com alongside the OAuth
110
- // callback (the old console.anthropic.com/v1/oauth/token now returns
111
- // Anthropic's standard 404 `{"error":{"type":"not_found_error","message":
112
- // "Not found"}}` — observed 2026-06). The redirect_uri MUST match what the
113
- // client is registered for AND match between authorize + token exchange.
114
- // Scopes mirror the live Claude Code authorize URL.
115
- tokenEndpoint: "https://platform.claude.com/v1/oauth/token",
116
- redirectUri: "https://platform.claude.com/oauth/code/callback",
117
- scopes: [
118
- "org:create_api_key",
119
- "user:profile",
120
- "user:inference",
121
- "user:sessions:claude_code",
122
- "user:mcp_servers",
123
- "user:file_upload"
124
- ]
125
- };
126
- var SETUP_TOKEN_CONFIG = {
127
- scopes: ["user:inference"]
128
- // Only inference permission, no API key creation
129
- };
130
- function generatePkce() {
131
- const codeVerifier = crypto.randomBytes(32).toString("base64url");
132
- const codeChallenge = crypto.createHash("sha256").update(codeVerifier).digest("base64url");
133
- const state = crypto.randomBytes(16).toString("hex");
134
- return { codeVerifier, codeChallenge, state };
135
- }
136
- function generateAuthParams() {
137
- const { codeVerifier, codeChallenge, state } = generatePkce();
138
- const params = new URLSearchParams({
139
- code: "true",
140
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
141
- response_type: "code",
142
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
143
- scope: CLAUDE_OAUTH_CONFIG.scopes.join(" "),
144
- code_challenge: codeChallenge,
145
- code_challenge_method: "S256",
146
- state
147
- });
148
- const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
149
- return { authUrl, codeVerifier, state };
150
- }
151
- function generateSetupTokenParams() {
152
- const { codeVerifier, codeChallenge, state } = generatePkce();
153
- const params = new URLSearchParams({
154
- code: "true",
155
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
156
- response_type: "code",
157
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
158
- scope: SETUP_TOKEN_CONFIG.scopes.join(" "),
159
- code_challenge: codeChallenge,
160
- code_challenge_method: "S256",
161
- state
162
- });
163
- const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
164
- return { authUrl, codeVerifier, state };
165
- }
166
- async function exchangeCodeForTokens(request, fetchImpl) {
167
- const { authorizationCode, codeVerifier, state } = request;
168
- const code = authorizationCode.split("#")[0]?.split("&")[0] ?? authorizationCode;
169
- const data = await postJson(
170
- fetchImpl,
171
- CLAUDE_OAUTH_CONFIG.tokenEndpoint,
172
- {
173
- grant_type: "authorization_code",
174
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
175
- code,
176
- code_verifier: codeVerifier,
177
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
178
- state
179
- },
180
- "Failed to parse token response",
181
- CLAUDE_TOKEN_HEADERS
182
- );
183
- return {
184
- accessToken: data.access_token,
185
- // The authorization_code grant always returns a refresh_token; the original
186
- // helper read it from an untyped `data` and declared the field `string`.
187
- refreshToken: data.refresh_token,
188
- expiresIn: data.expires_in,
189
- scopes: data.scope?.split(" ") || CLAUDE_OAUTH_CONFIG.scopes
190
- };
191
- }
192
- async function exchangeSetupTokenCode(request, fetchImpl) {
193
- const { authorizationCode, codeVerifier, state } = request;
194
- const code = authorizationCode.split("#")[0]?.split("&")[0] ?? authorizationCode;
195
- const data = await postJson(
196
- fetchImpl,
197
- CLAUDE_OAUTH_CONFIG.tokenEndpoint,
198
- {
199
- grant_type: "authorization_code",
200
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
201
- code,
202
- code_verifier: codeVerifier,
203
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
204
- state
205
- },
206
- "Failed to parse setup token response",
207
- CLAUDE_TOKEN_HEADERS
208
- );
209
- return {
210
- accessToken: data.access_token,
211
- expiresIn: data.expires_in,
212
- scopes: data.scope?.split(" ") || SETUP_TOKEN_CONFIG.scopes
213
- };
214
- }
215
- async function refreshAccessToken(refreshToken, fetchImpl) {
216
- const data = await postJson(
217
- fetchImpl,
218
- CLAUDE_OAUTH_CONFIG.tokenEndpoint,
219
- {
220
- grant_type: "refresh_token",
221
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
222
- refresh_token: refreshToken
223
- },
224
- "Failed to parse refresh response",
225
- CLAUDE_TOKEN_HEADERS
226
- );
227
- return {
228
- accessToken: data.access_token,
229
- refreshToken: data.refresh_token || refreshToken,
230
- expiresIn: data.expires_in
231
- };
232
- }
233
-
234
- // src/oauth/flows/codex.ts
235
- var codex_exports = {};
236
- __export(codex_exports, {
237
- exchangeCodeForTokens: () => exchangeCodeForTokens2,
238
- generateAuthParams: () => generateAuthParams2,
239
- refreshAccessToken: () => refreshAccessToken2
240
- });
241
- import crypto2 from "crypto";
242
- var CODEX_OAUTH_CONFIG = {
243
- clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
244
- authorizationEndpoint: "https://auth.openai.com/oauth/authorize",
245
- tokenEndpoint: "https://auth.openai.com/oauth/token",
246
- redirectUri: "http://localhost:1455/auth/callback",
247
- scopes: ["openid", "profile", "email", "offline_access"]
248
- };
249
- function generateAuthParams2() {
250
- const codeVerifier = crypto2.randomBytes(64).toString("hex");
251
- const codeChallenge = crypto2.createHash("sha256").update(codeVerifier).digest("base64url");
252
- const state = crypto2.randomBytes(16).toString("hex");
253
- const params = new URLSearchParams({
254
- response_type: "code",
255
- client_id: CODEX_OAUTH_CONFIG.clientId,
256
- redirect_uri: CODEX_OAUTH_CONFIG.redirectUri,
257
- scope: CODEX_OAUTH_CONFIG.scopes.join(" "),
258
- code_challenge: codeChallenge,
259
- code_challenge_method: "S256",
260
- state
261
- });
262
- const authUrl = `${CODEX_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
263
- return { authUrl, codeVerifier, state };
264
- }
265
- async function exchangeCodeForTokens2(request, fetchImpl) {
266
- const { authorizationCode, codeVerifier } = request;
267
- const params = new URLSearchParams({
268
- grant_type: "authorization_code",
269
- client_id: CODEX_OAUTH_CONFIG.clientId,
270
- code: authorizationCode,
271
- code_verifier: codeVerifier,
272
- redirect_uri: CODEX_OAUTH_CONFIG.redirectUri
273
- });
274
- const data = await postForm(
275
- fetchImpl,
276
- CODEX_OAUTH_CONFIG.tokenEndpoint,
277
- params,
278
- "Failed to parse token response"
279
- );
280
- return {
281
- accessToken: data.access_token,
282
- // authorization_code grant returns both; the original helper read them from
283
- // an untyped `data` and declared the fields `string`.
284
- refreshToken: data.refresh_token,
285
- idToken: data.id_token,
286
- expiresIn: data.expires_in
287
- };
288
- }
289
- async function refreshAccessToken2(refreshToken, fetchImpl) {
290
- const params = new URLSearchParams({
291
- grant_type: "refresh_token",
292
- client_id: CODEX_OAUTH_CONFIG.clientId,
293
- refresh_token: refreshToken,
294
- scope: "openid profile email"
295
- });
296
- const data = await postForm(
297
- fetchImpl,
298
- CODEX_OAUTH_CONFIG.tokenEndpoint,
299
- params,
300
- "Failed to parse refresh response"
301
- );
302
- return {
303
- accessToken: data.access_token,
304
- idToken: data.id_token,
305
- refreshToken: data.refresh_token || refreshToken,
306
- expiresIn: data.expires_in || 3600
307
- };
308
- }
309
-
310
- // src/oauth/flows/gemini.ts
311
- var gemini_exports = {};
312
- __export(gemini_exports, {
313
- exchangeCodeForTokens: () => exchangeCodeForTokens3,
314
- generateAuthParams: () => generateAuthParams3,
315
- refreshAccessToken: () => refreshAccessToken3
316
- });
317
- import crypto3 from "crypto";
318
- var GEMINI_OAUTH_CONFIG = {
319
- clientId: "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com",
320
- // The Gemini CLI's *public* installed-app OAuth client secret (mirrors the
321
- // upstream CLI). Per Google's OAuth docs, native-app client secrets are not
322
- // treated as confidential — not a leaked key.
323
- clientSecret: "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",
324
- // allowlist-secret
325
- authorizationEndpoint: "https://accounts.google.com/o/oauth2/v2/auth",
326
- tokenEndpoint: "https://oauth2.googleapis.com/token",
327
- redirectUri: "urn:ietf:wg:oauth:2.0:oob",
328
- scopes: ["https://www.googleapis.com/auth/cloud-platform"]
329
- };
330
- function generateAuthParams3() {
331
- const codeVerifier = crypto3.randomBytes(32).toString("base64url");
332
- const codeChallenge = crypto3.createHash("sha256").update(codeVerifier).digest("base64url");
333
- const state = crypto3.randomBytes(16).toString("hex");
334
- const params = new URLSearchParams({
335
- client_id: GEMINI_OAUTH_CONFIG.clientId,
336
- redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri,
337
- scope: GEMINI_OAUTH_CONFIG.scopes.join(" "),
338
- response_type: "code",
339
- code_challenge: codeChallenge,
340
- code_challenge_method: "S256",
341
- state,
342
- access_type: "offline",
343
- prompt: "consent"
344
- });
345
- const authUrl = `${GEMINI_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
346
- return { authUrl, codeVerifier, state };
347
- }
348
- async function exchangeCodeForTokens3(authorizationCode, codeVerifier, fetchImpl) {
349
- const params = new URLSearchParams({
350
- grant_type: "authorization_code",
351
- client_id: GEMINI_OAUTH_CONFIG.clientId,
352
- client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
353
- code: authorizationCode,
354
- code_verifier: codeVerifier,
355
- redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri
356
- });
357
- const data = await postForm(
358
- fetchImpl,
359
- GEMINI_OAUTH_CONFIG.tokenEndpoint,
360
- params,
361
- "Failed to parse token response"
362
- );
363
- return {
364
- accessToken: data.access_token,
365
- // authorization_code grant returns a refresh_token; the original helper read
366
- // it from an untyped `data` and declared the field `string`.
367
- refreshToken: data.refresh_token,
368
- expiresIn: data.expires_in
369
- };
370
- }
371
- async function refreshAccessToken3(refreshToken, fetchImpl) {
372
- const params = new URLSearchParams({
373
- grant_type: "refresh_token",
374
- client_id: GEMINI_OAUTH_CONFIG.clientId,
375
- client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
376
- refresh_token: refreshToken
377
- });
378
- const data = await postForm(
379
- fetchImpl,
380
- GEMINI_OAUTH_CONFIG.tokenEndpoint,
381
- params,
382
- "Failed to parse refresh response"
383
- );
384
- return {
385
- accessToken: data.access_token,
386
- expiresIn: data.expires_in
387
- };
388
- }
389
-
390
- export {
391
- claude_exports,
392
- codex_exports,
393
- gemini_exports
394
- };