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