openai-codex-oauth 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.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * @file types.ts
3
+ *
4
+ * Core type definitions for the OpenAI Codex OAuth library.
5
+ * These types define the contract for authentication, token management,
6
+ * and configuration across all modules.
7
+ */
8
+ /**
9
+ * Type alias for the global fetch function signature.
10
+ * Used to allow custom fetch implementations in various environments.
11
+ */
12
+ type FetchLike = typeof globalThis.fetch;
13
+ /**
14
+ * OAuth credentials used to call the OpenAI Codex backend.
15
+ * Treat these as password-equivalent secrets.
16
+ */
17
+ type OpenAIOAuthTokens = {
18
+ /** Bearer token sent to the Codex backend. */
19
+ accessToken: string;
20
+ /** Refresh token used to obtain a new access token before expiry. */
21
+ refreshToken?: string;
22
+ /** Access-token expiry as epoch milliseconds. */
23
+ expiresAt?: number;
24
+ /** Optional OpenID token. Used to derive `accountId` when available. */
25
+ idToken?: string;
26
+ /** ChatGPT account id required by the Codex backend. */
27
+ accountId?: string;
28
+ };
29
+ /** Async storage interface for loading and persisting OAuth credentials. */
30
+ type TokenStore = {
31
+ /** Load the latest known credentials. Return `undefined` when the user is not signed in. */
32
+ load(): Promise<OpenAIOAuthTokens | undefined>;
33
+ /** Persist new credentials after sign-in or refresh. */
34
+ save(tokens: OpenAIOAuthTokens): Promise<void>;
35
+ };
36
+ /** In-progress OpenAI Codex device authorization flow. */
37
+ type OpenAIDeviceFlow = {
38
+ providerId: 'openai';
39
+ /** URL the user should open to authorize the device flow. */
40
+ url: string;
41
+ /** User code to enter on the authorization page. */
42
+ code: string;
43
+ /** Human-readable instruction string for command-line or app UI. */
44
+ instructions: string;
45
+ /** Poll until authorization completes, exchange the grant, and return OAuth tokens. */
46
+ complete(): Promise<OpenAIOAuthTokens>;
47
+ };
48
+ /** Options for starting OpenAI's Codex device OAuth flow. */
49
+ type OpenAIDeviceFlowOptions = {
50
+ /** Custom fetch implementation, useful for tests and non-standard runtimes. */
51
+ fetch?: FetchLike;
52
+ /** Clock override returning epoch milliseconds. */
53
+ now?: () => number;
54
+ /** Sleep override used between polling attempts. */
55
+ sleep?: (ms: number) => Promise<void>;
56
+ /** OAuth client id. Defaults to the Codex client id. */
57
+ clientId?: string;
58
+ /** OAuth issuer. Defaults to `https://auth.openai.com`. */
59
+ issuer?: string;
60
+ /** Optional store that receives tokens after successful authorization. */
61
+ tokenStore?: TokenStore;
62
+ };
63
+ /** Shared settings for Codex OAuth fetch, client, and AI SDK provider creation. */
64
+ type OpenAIOAuthSettings = {
65
+ /** Custom fetch implementation for both token refresh and Codex requests. */
66
+ fetch?: FetchLike;
67
+ /** Secure token storage used to load and save refreshed credentials. */
68
+ tokenStore?: TokenStore;
69
+ /** Inline tokens for scripts/tests. Prefer `tokenStore` for production apps. */
70
+ tokens?: OpenAIOAuthTokens;
71
+ /** OAuth client id. Defaults to the Codex client id. */
72
+ clientId?: string;
73
+ /** OAuth issuer. Defaults to `https://auth.openai.com`. */
74
+ issuer?: string;
75
+ /** Override token endpoint for refresh. */
76
+ tokenUrl?: string;
77
+ /** Codex backend base URL. Defaults to `https://chatgpt.com/backend-api/codex`. */
78
+ baseURL?: string;
79
+ /** Browser proxy base URL for Codex requests. Defaults to `/api/proxy/openai/codex` in browsers. Pass `false` to disable. */
80
+ browserProxyBaseUrl?: string | false;
81
+ /** Additional headers sent to the Codex backend before OAuth headers are applied. */
82
+ headers?: Record<string, string>;
83
+ /** Default `instructions` value for Responses requests that omit it. */
84
+ instructions?: string;
85
+ /** Default OpenAI Responses `store` value. Defaults to `false`. */
86
+ store?: boolean;
87
+ /** Upstream `originator` header. Pass `false` to omit it. */
88
+ originator?: string | false;
89
+ /** Refresh access tokens this many milliseconds before expiry. */
90
+ refreshMarginMs?: number;
91
+ /** Clock override returning epoch milliseconds. */
92
+ now?: () => number;
93
+ /** Called after a successful token refresh. */
94
+ onTokens?: (tokens: OpenAIOAuthTokens) => void | Promise<void>;
95
+ };
96
+ /** Settings for the AI SDK provider factory. */
97
+ type OpenAIOAuthProviderSettings = OpenAIOAuthSettings & {
98
+ /** Provider name exposed to AI SDK telemetry and metadata. */
99
+ name?: string;
100
+ };
101
+ /** Error class used for OAuth, token, and credential setup failures. */
102
+ declare class OpenAIOAuthError extends Error {
103
+ readonly code: string;
104
+ constructor(code: string, message: string, options?: ErrorOptions);
105
+ }
106
+
107
+ export { type FetchLike as F, type OpenAIDeviceFlow as O, type TokenStore as T, type OpenAIDeviceFlowOptions as a, OpenAIOAuthError as b, type OpenAIOAuthProviderSettings as c, type OpenAIOAuthSettings as d, type OpenAIOAuthTokens as e };
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "openai-codex-oauth",
3
+ "version": "0.0.0",
4
+ "description": "OpenAI Codex OAuth provider and token helpers for the Vercel AI SDK.",
5
+ "author": "respectmathias",
6
+ "type": "module",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/RespectMathias/openai-codex-oauth.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/RespectMathias/openai-codex-oauth/issues"
14
+ },
15
+ "homepage": "https://github.com/RespectMathias/openai-codex-oauth#readme",
16
+ "sideEffects": false,
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "files": [
20
+ "dist",
21
+ "README.md",
22
+ "LICENSE",
23
+ "NOTICE"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./node": {
32
+ "types": "./dist/node/index.d.ts",
33
+ "import": "./dist/node/index.js",
34
+ "default": "./dist/node/index.js"
35
+ },
36
+ "./proxy": {
37
+ "types": "./dist/proxy.d.ts",
38
+ "import": "./dist/proxy.js",
39
+ "default": "./dist/proxy.js"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "scripts": {
44
+ "build": "tsup --tsconfig tsconfig.json",
45
+ "typecheck": "tsc --noEmit",
46
+ "test": "vitest run"
47
+ },
48
+ "peerDependencies": {
49
+ "@ai-sdk/openai": ">=3.0.0",
50
+ "@ai-sdk/provider": ">=3.0.0",
51
+ "ai": ">=6.0.0"
52
+ },
53
+ "devDependencies": {
54
+ "@ai-sdk/openai": "^3.0.64",
55
+ "@ai-sdk/provider": "^3.0.10",
56
+ "@types/node": "^20.17.24",
57
+ "ai": "^6.0.184",
58
+ "tsup": "^8.5.0",
59
+ "typescript": "^5.8.3",
60
+ "vitest": "^4.1.5"
61
+ },
62
+ "engines": {
63
+ "node": ">=18"
64
+ },
65
+ "publishConfig": {
66
+ "access": "public",
67
+ "provenance": false
68
+ },
69
+ "keywords": [
70
+ "ai-sdk",
71
+ "openai",
72
+ "oauth",
73
+ "codex",
74
+ "vercel",
75
+ "chatgpt"
76
+ ]
77
+ }