@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/oauth.js CHANGED
@@ -1,361 +1,8 @@
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 stays on console.anthropic.com (still the live value —
81
- // matches the official Claude Code CLI / claude-relay-service reference); only
82
- // the OAuth callback moved to platform.claude.com (2026). The redirect_uri MUST
83
- // match what the client is registered for AND match between authorize + token
84
- // exchange. Scopes mirror the live Claude Code authorize URL.
85
- tokenEndpoint: "https://console.anthropic.com/v1/oauth/token",
86
- redirectUri: "https://platform.claude.com/oauth/code/callback",
87
- scopes: [
88
- "org:create_api_key",
89
- "user:profile",
90
- "user:inference",
91
- "user:sessions:claude_code",
92
- "user:mcp_servers",
93
- "user:file_upload"
94
- ]
95
- };
96
- var SETUP_TOKEN_CONFIG = {
97
- scopes: ["user:inference"]
98
- // Only inference permission, no API key creation
99
- };
100
- function generatePkce() {
101
- const codeVerifier = crypto.randomBytes(32).toString("base64url");
102
- const codeChallenge = crypto.createHash("sha256").update(codeVerifier).digest("base64url");
103
- const state = crypto.randomBytes(16).toString("hex");
104
- return { codeVerifier, codeChallenge, state };
105
- }
106
- function generateAuthParams() {
107
- const { codeVerifier, codeChallenge, state } = generatePkce();
108
- const params = new URLSearchParams({
109
- code: "true",
110
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
111
- response_type: "code",
112
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
113
- scope: CLAUDE_OAUTH_CONFIG.scopes.join(" "),
114
- code_challenge: codeChallenge,
115
- code_challenge_method: "S256",
116
- state
117
- });
118
- const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
119
- return { authUrl, codeVerifier, state };
120
- }
121
- function generateSetupTokenParams() {
122
- const { codeVerifier, codeChallenge, state } = generatePkce();
123
- const params = new URLSearchParams({
124
- code: "true",
125
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
126
- response_type: "code",
127
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
128
- scope: SETUP_TOKEN_CONFIG.scopes.join(" "),
129
- code_challenge: codeChallenge,
130
- code_challenge_method: "S256",
131
- state
132
- });
133
- const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
134
- return { authUrl, codeVerifier, state };
135
- }
136
- async function exchangeCodeForTokens(request, fetchImpl) {
137
- const { authorizationCode, codeVerifier, state } = request;
138
- const code = authorizationCode.split("#")[0]?.split("&")[0] ?? authorizationCode;
139
- const data = await postJson(
140
- fetchImpl,
141
- CLAUDE_OAUTH_CONFIG.tokenEndpoint,
142
- {
143
- grant_type: "authorization_code",
144
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
145
- code,
146
- code_verifier: codeVerifier,
147
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
148
- state
149
- },
150
- "Failed to parse token response",
151
- CLAUDE_TOKEN_HEADERS
152
- );
153
- return {
154
- accessToken: data.access_token,
155
- // The authorization_code grant always returns a refresh_token; the original
156
- // helper read it from an untyped `data` and declared the field `string`.
157
- refreshToken: data.refresh_token,
158
- expiresIn: data.expires_in,
159
- scopes: data.scope?.split(" ") || CLAUDE_OAUTH_CONFIG.scopes
160
- };
161
- }
162
- async function exchangeSetupTokenCode(request, fetchImpl) {
163
- const { authorizationCode, codeVerifier, state } = request;
164
- const code = authorizationCode.split("#")[0]?.split("&")[0] ?? authorizationCode;
165
- const data = await postJson(
166
- fetchImpl,
167
- CLAUDE_OAUTH_CONFIG.tokenEndpoint,
168
- {
169
- grant_type: "authorization_code",
170
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
171
- code,
172
- code_verifier: codeVerifier,
173
- redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
174
- state
175
- },
176
- "Failed to parse setup token response",
177
- CLAUDE_TOKEN_HEADERS
178
- );
179
- return {
180
- accessToken: data.access_token,
181
- expiresIn: data.expires_in,
182
- scopes: data.scope?.split(" ") || SETUP_TOKEN_CONFIG.scopes
183
- };
184
- }
185
- async function refreshAccessToken(refreshToken, fetchImpl) {
186
- const data = await postJson(
187
- fetchImpl,
188
- CLAUDE_OAUTH_CONFIG.tokenEndpoint,
189
- {
190
- grant_type: "refresh_token",
191
- client_id: CLAUDE_OAUTH_CONFIG.clientId,
192
- refresh_token: refreshToken
193
- },
194
- "Failed to parse refresh response",
195
- CLAUDE_TOKEN_HEADERS
196
- );
197
- return {
198
- accessToken: data.access_token,
199
- refreshToken: data.refresh_token || refreshToken,
200
- expiresIn: data.expires_in
201
- };
202
- }
203
-
204
- // src/oauth/flows/codex.ts
205
- var codex_exports = {};
206
- __export(codex_exports, {
207
- exchangeCodeForTokens: () => exchangeCodeForTokens2,
208
- generateAuthParams: () => generateAuthParams2,
209
- refreshAccessToken: () => refreshAccessToken2
210
- });
211
- import crypto2 from "crypto";
212
- var CODEX_OAUTH_CONFIG = {
213
- clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
214
- authorizationEndpoint: "https://auth.openai.com/oauth/authorize",
215
- tokenEndpoint: "https://auth.openai.com/oauth/token",
216
- redirectUri: "http://localhost:1455/auth/callback",
217
- scopes: ["openid", "profile", "email", "offline_access"]
218
- };
219
- function generateAuthParams2() {
220
- const codeVerifier = crypto2.randomBytes(64).toString("hex");
221
- const codeChallenge = crypto2.createHash("sha256").update(codeVerifier).digest("base64url");
222
- const state = crypto2.randomBytes(16).toString("hex");
223
- const params = new URLSearchParams({
224
- response_type: "code",
225
- client_id: CODEX_OAUTH_CONFIG.clientId,
226
- redirect_uri: CODEX_OAUTH_CONFIG.redirectUri,
227
- scope: CODEX_OAUTH_CONFIG.scopes.join(" "),
228
- code_challenge: codeChallenge,
229
- code_challenge_method: "S256",
230
- state
231
- });
232
- const authUrl = `${CODEX_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
233
- return { authUrl, codeVerifier, state };
234
- }
235
- async function exchangeCodeForTokens2(request, fetchImpl) {
236
- const { authorizationCode, codeVerifier } = request;
237
- const params = new URLSearchParams({
238
- grant_type: "authorization_code",
239
- client_id: CODEX_OAUTH_CONFIG.clientId,
240
- code: authorizationCode,
241
- code_verifier: codeVerifier,
242
- redirect_uri: CODEX_OAUTH_CONFIG.redirectUri
243
- });
244
- const data = await postForm(
245
- fetchImpl,
246
- CODEX_OAUTH_CONFIG.tokenEndpoint,
247
- params,
248
- "Failed to parse token response"
249
- );
250
- return {
251
- accessToken: data.access_token,
252
- // authorization_code grant returns both; the original helper read them from
253
- // an untyped `data` and declared the fields `string`.
254
- refreshToken: data.refresh_token,
255
- idToken: data.id_token,
256
- expiresIn: data.expires_in
257
- };
258
- }
259
- async function refreshAccessToken2(refreshToken, fetchImpl) {
260
- const params = new URLSearchParams({
261
- grant_type: "refresh_token",
262
- client_id: CODEX_OAUTH_CONFIG.clientId,
263
- refresh_token: refreshToken,
264
- scope: "openid profile email"
265
- });
266
- const data = await postForm(
267
- fetchImpl,
268
- CODEX_OAUTH_CONFIG.tokenEndpoint,
269
- params,
270
- "Failed to parse refresh response"
271
- );
272
- return {
273
- accessToken: data.access_token,
274
- idToken: data.id_token,
275
- refreshToken: data.refresh_token || refreshToken,
276
- expiresIn: data.expires_in || 3600
277
- };
278
- }
279
-
280
- // src/oauth/flows/gemini.ts
281
- var gemini_exports = {};
282
- __export(gemini_exports, {
283
- exchangeCodeForTokens: () => exchangeCodeForTokens3,
284
- generateAuthParams: () => generateAuthParams3,
285
- refreshAccessToken: () => refreshAccessToken3
286
- });
287
- import crypto3 from "crypto";
288
- var GEMINI_OAUTH_CONFIG = {
289
- clientId: "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com",
290
- // The Gemini CLI's *public* installed-app OAuth client secret (mirrors the
291
- // upstream CLI). Per Google's OAuth docs, native-app client secrets are not
292
- // treated as confidential — not a leaked key.
293
- clientSecret: "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",
294
- // allowlist-secret
295
- authorizationEndpoint: "https://accounts.google.com/o/oauth2/v2/auth",
296
- tokenEndpoint: "https://oauth2.googleapis.com/token",
297
- redirectUri: "urn:ietf:wg:oauth:2.0:oob",
298
- scopes: ["https://www.googleapis.com/auth/cloud-platform"]
299
- };
300
- function generateAuthParams3() {
301
- const codeVerifier = crypto3.randomBytes(32).toString("base64url");
302
- const codeChallenge = crypto3.createHash("sha256").update(codeVerifier).digest("base64url");
303
- const state = crypto3.randomBytes(16).toString("hex");
304
- const params = new URLSearchParams({
305
- client_id: GEMINI_OAUTH_CONFIG.clientId,
306
- redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri,
307
- scope: GEMINI_OAUTH_CONFIG.scopes.join(" "),
308
- response_type: "code",
309
- code_challenge: codeChallenge,
310
- code_challenge_method: "S256",
311
- state,
312
- access_type: "offline",
313
- prompt: "consent"
314
- });
315
- const authUrl = `${GEMINI_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
316
- return { authUrl, codeVerifier, state };
317
- }
318
- async function exchangeCodeForTokens3(authorizationCode, codeVerifier, fetchImpl) {
319
- const params = new URLSearchParams({
320
- grant_type: "authorization_code",
321
- client_id: GEMINI_OAUTH_CONFIG.clientId,
322
- client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
323
- code: authorizationCode,
324
- code_verifier: codeVerifier,
325
- redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri
326
- });
327
- const data = await postForm(
328
- fetchImpl,
329
- GEMINI_OAUTH_CONFIG.tokenEndpoint,
330
- params,
331
- "Failed to parse token response"
332
- );
333
- return {
334
- accessToken: data.access_token,
335
- // authorization_code grant returns a refresh_token; the original helper read
336
- // it from an untyped `data` and declared the field `string`.
337
- refreshToken: data.refresh_token,
338
- expiresIn: data.expires_in
339
- };
340
- }
341
- async function refreshAccessToken3(refreshToken, fetchImpl) {
342
- const params = new URLSearchParams({
343
- grant_type: "refresh_token",
344
- client_id: GEMINI_OAUTH_CONFIG.clientId,
345
- client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
346
- refresh_token: refreshToken
347
- });
348
- const data = await postForm(
349
- fetchImpl,
350
- GEMINI_OAUTH_CONFIG.tokenEndpoint,
351
- params,
352
- "Failed to parse refresh response"
353
- );
354
- return {
355
- accessToken: data.access_token,
356
- expiresIn: data.expires_in
357
- };
358
- }
1
+ import {
2
+ claude_exports,
3
+ codex_exports,
4
+ gemini_exports
5
+ } from "./chunk-IXGHVMZB.js";
359
6
  export {
360
7
  claude_exports as claudeOAuth,
361
8
  codex_exports as codexOAuth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnicross/subscriptions",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Omnicross subscription-as-provider auth strategies, OAuth flows, and the OpenCodeGo scenario dispatcher.",
5
5
  "license": "MIT",
6
6
  "author": "Sayo (https://github.com/Dumoedss)",
@@ -53,6 +53,7 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@omnicross/contracts": "^0.1.0",
56
+ "@omnicross/core": "^0.1.0",
56
57
  "js-tiktoken": "^1.0.21"
57
58
  }
58
59
  }