oauth.do 0.1.14 → 0.2.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 @@
1
+ {"version":3,"sources":["../src/react.tsx"],"names":["WorkOSAuthKitProvider","useWorkOSAuth","WorkOSApiKeys","WorkOSUsersManagement","WorkOSUserProfile"],"mappings":";;;;AAsEA,IAAM,eAAA,GAAkB;AAAA,EACtB,QAAA,EAAU,mCAAA;AAAA,EACV,MAAA,EAAQ,iBAAA;AAAA,EACR,aAAA,EAAe;AACjB,CAAA;AAYA,IAAM,cAAA,GAAiB,cAAmC,eAAe,CAAA;AAElE,SAAS,gBAAA,GAAwC;AACtD,EAAA,OAAO,WAAW,cAAc,CAAA;AAClC;AAgCO,SAAS,eAAA,CAAgB;AAAA,EAC9B,QAAA;AAAA,EACA,WAAW,eAAA,CAAgB,QAAA;AAAA,EAC3B,SAAS,eAAA,CAAgB,MAAA;AAAA,EACzB,gBAAgB,eAAA,CAAgB;AAClC,CAAA,EAAsC;AACpC,EAAA,MAAM,MAAA,GAAS,EAAE,QAAA,EAAU,MAAA,EAAQ,aAAA,EAAc;AAEjD,EAAA,uBACE,KAAA,CAAA,aAAA,CAAC,cAAA,CAAe,QAAA,EAAf,EAAwB,KAAA,EAAO,MAAA,EAAA,kBAC9B,KAAA,CAAA,aAAA,CAACA,eAAA,EAAA,EAAsB,QAAA,EAAA,kBACrB,KAAA,CAAA,aAAA,CAAC,aAAA,EAAA,IAAA,EACE,QACH,CACF,CACF,CAAA;AAEJ;AAuBO,SAAS,OAAA,GAAqB;AACnC,EAAA,OAAOC,SAAA,EAAc;AACvB;AA4BO,SAAS,OAAA,CAAQ,EAAE,SAAA,EAAU,EAA8B;AAChE,EAAA,uBAAO,KAAA,CAAA,aAAA,CAACC,aAAc,SAAA,EAAsB,CAAA;AAC9C;AAsBO,SAAS,eAAA,CAAgB,EAAE,SAAA,EAAU,EAAsC;AAChF,EAAA,uBAAO,K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AO,OAAO,MAAA,KAAW,WAAA,EAAa;AACvD,MAAA,MAAA,CAAO,SAAS,IAAA,GAAO,UAAA;AAAA,IACzB;AAAA,EACF,CAAA;AAEA,EAAA,uBACE,KAAA,CAAA,aAAA,CAAC,QAAA,EAAA,EAAO,OAAA,EAAS,WAAA,EAAa,aAC3B,QACH,CAAA;AAEJ","file":"react.js","sourcesContent":["/**\n * oauth.do/react - React components for authentication\n *\n * Wraps WorkOS AuthKit widgets with oauth.do configuration.\n * Pre-configured with oauth.do WorkOS client ID.\n *\n * @packageDocumentation\n */\n\n'use client'\n\nimport {\n WorkOsWidgets,\n ApiKeys as WorkOSApiKeys,\n UsersManagement as WorkOSUsersManagement,\n UserProfile as WorkOSUserProfile\n} from '@workos-inc/widgets'\nimport {\n AuthKitProvider as WorkOSAuthKitProvider,\n useAuth as useWorkOSAuth,\n type Impersonator,\n type User,\n type AuthenticationMethod\n} from '@workos-inc/authkit-react'\n\n/**\n * Auth token can be a string or a function that returns a Promise<string>\n */\nexport type AuthToken = string | (() => Promise<string>)\nimport React, { createContext, useContext, type ReactNode } from 'react'\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Auth Types (re-exported from authkit-react context)\n// ═══════════════════════════════════════════════════════════════════════════\n\n/**\n * Options for switching organization\n */\nexport interface SwitchToOrganizationOptions {\n organizationId: string\n signInOpts?: {\n screenHint?: 'sign-in' | 'sign-up'\n loginHint?: string\n }\n}\n\n/**\n * Auth state and methods returned by useAuth hook\n */\nexport interface AuthState {\n isLoading: boolean\n user: User | null\n role: string | null\n roles: string[] | null\n organizationId: string | null\n permissions: string[]\n featureFlags: string[]\n impersonator: Impersonator | null\n authenticationMethod: AuthenticationMethod | null\n signIn: () => void\n signUp: () => void\n getUser: () => User | null\n getAccessToken: () => Promise<string>\n signOut: () => void\n switchToOrganization: (options: SwitchToOrganizationOptions) => Promise<void>\n getSignInUrl: () => Promise<string>\n getSignUpUrl: () => Promise<string>\n}\n\n// oauth.do default configuration\nconst OAUTH_DO_CONFIG = {\n clientId: 'client_01JQYTRXK9ZPD8JPJTKDCRB656',\n apiUrl: 'https://apis.do',\n authKitDomain: 'login.oauth.do',\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Context\n// ═══════════════════════════════════════════════════════════════════════════\n\ninterface OAuthDoContextValue {\n clientId: string\n apiUrl: string\n authKitDomain: string\n}\n\nconst OAuthDoContext = createContext<OAuthDoContextValue>(OAUTH_DO_CONFIG)\n\nexport function useOAuthDoConfig(): OAuthDoContextValue {\n return useContext(OAuthDoContext)\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Provider\n// ═══════════════════════════════════════════════════════════════════════════\n\nexport interface OAuthDoProviderProps {\n children: ReactNode\n /** Override the default client ID */\n clientId?: string\n /** Override the API URL */\n apiUrl?: string\n /** Override the AuthKit domain */\n authKitDomain?: string\n}\n\n/**\n * OAuth.do Provider - wraps your app with authentication context\n *\n * @example\n * ```tsx\n * import { OAuthDoProvider } from 'oauth.do/react'\n *\n * export default function App({ children }) {\n * return (\n * <OAuthDoProvider>\n * {children}\n * </OAuthDoProvider>\n * )\n * }\n * ```\n */\nexport function OAuthDoProvider({\n children,\n clientId = OAUTH_DO_CONFIG.clientId,\n apiUrl = OAUTH_DO_CONFIG.apiUrl,\n authKitDomain = OAUTH_DO_CONFIG.authKitDomain,\n}: OAuthDoProviderProps): JSX.Element {\n const config = { clientId, apiUrl, authKitDomain }\n\n return (\n <OAuthDoContext.Provider value={config}>\n <WorkOSAuthKitProvider clientId={clientId}>\n <WorkOsWidgets>\n {children}\n </WorkOsWidgets>\n </WorkOSAuthKitProvider>\n </OAuthDoContext.Provider>\n )\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Hooks\n// ═══════════════════════════════════════════════════════════════════════════\n\n/**\n * useAuth hook - access current user and auth state\n *\n * @example\n * ```tsx\n * import { useAuth } from 'oauth.do/react'\n *\n * function UserGreeting() {\n * const { user, isLoading } = useAuth()\n *\n * if (isLoading) return <span>Loading...</span>\n * if (!user) return <span>Please sign in</span>\n *\n * return <span>Hello, {user.firstName}!</span>\n * }\n * ```\n */\nexport function useAuth(): AuthState {\n return useWorkOSAuth() as AuthState\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Widgets\n// ═══════════════════════════════════════════════════════════════════════════\n\nexport interface ApiKeysProps {\n /** Auth token for the widget (from useAuth().getAccessToken or server-generated) */\n authToken: AuthToken\n}\n\n/**\n * API Keys Widget - manage API keys for your organization\n *\n * Requires the `widgets:api-keys:manage` permission.\n *\n * @example\n * ```tsx\n * import { ApiKeys, useAuth } from 'oauth.do/react'\n *\n * function ApiKeysPage() {\n * const { user, getAccessToken } = useAuth()\n * if (!user) return <p>Please sign in</p>\n *\n * return <ApiKeys authToken={getAccessToken} />\n * }\n * ```\n */\nexport function ApiKeys({ authToken }: ApiKeysProps): JSX.Element {\n return <WorkOSApiKeys authToken={authToken} />\n}\n\nexport interface UsersManagementProps {\n /** Auth token for the widget */\n authToken: AuthToken\n}\n\n/**\n * Users Management Widget - invite, remove, and manage users\n *\n * @example\n * ```tsx\n * import { UsersManagement, useAuth } from 'oauth.do/react'\n *\n * function UsersPage() {\n * const { user, getAccessToken } = useAuth()\n * if (!user) return <p>Please sign in</p>\n *\n * return <UsersManagement authToken={getAccessToken} />\n * }\n * ```\n */\nexport function UsersManagement({ authToken }: UsersManagementProps): JSX.Element {\n return <WorkOSUsersManagement authToken={authToken} />\n}\n\nexport interface UserProfileProps {\n /** Auth token for the widget */\n authToken: AuthToken\n}\n\n/**\n * User Profile Widget - view and edit user profile\n *\n * @example\n * ```tsx\n * import { UserProfile, useAuth } from 'oauth.do/react'\n *\n * function ProfilePage() {\n * const { user, getAccessToken } = useAuth()\n * if (!user) return <p>Please sign in</p>\n *\n * return <UserProfile authToken={getAccessToken} />\n * }\n * ```\n */\nexport function UserProfile({ authToken }: UserProfileProps): JSX.Element {\n return <WorkOSUserProfile authToken={authToken} />\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Login Components\n// ═══════════════════════════════════════════════════════════════════════════\n\nexport interface SignInButtonProps {\n children?: ReactNode\n className?: string\n redirectTo?: string\n}\n\n/**\n * Sign In Button - redirects to oauth.do login\n *\n * @example\n * ```tsx\n * import { SignInButton } from 'oauth.do/react'\n *\n * function Header() {\n * return <SignInButton>Sign In</SignInButton>\n * }\n * ```\n */\nexport function SignInButton({\n children = 'Sign In',\n className,\n redirectTo = typeof window !== 'undefined' ? window.location.href : '/',\n}: SignInButtonProps): JSX.Element {\n const { authKitDomain, clientId } = useOAuthDoConfig()\n\n const handleClick = () => {\n const url = new URL(`https://${authKitDomain}`)\n url.searchParams.set('client_id', clientId)\n url.searchParams.set('redirect_uri', redirectTo)\n url.searchParams.set('response_type', 'code')\n window.location.href = url.toString()\n }\n\n return (\n <button onClick={handleClick} className={className}>\n {children}\n </button>\n )\n}\n\nexport interface SignOutButtonProps {\n children?: ReactNode\n className?: string\n redirectTo?: string\n}\n\n/**\n * Sign Out Button - clears auth state and optionally redirects\n *\n * @example\n * ```tsx\n * import { SignOutButton } from 'oauth.do/react'\n *\n * function Header() {\n * return <SignOutButton>Sign Out</SignOutButton>\n * }\n * ```\n */\nexport function SignOutButton({\n children = 'Sign Out',\n className,\n redirectTo = '/',\n}: SignOutButtonProps): JSX.Element {\n const { signOut } = useAuth()\n\n const handleClick = () => {\n signOut()\n // Redirect after signOut if a custom redirectTo is provided\n if (redirectTo !== '/' && typeof window !== 'undefined') {\n window.location.href = redirectTo\n }\n }\n\n return (\n <button onClick={handleClick} className={className}>\n {children}\n </button>\n )\n}\n\n// ═══════════════════════════════════════════════════════════════════════════\n// Re-exports\n// ═══════════════════════════════════════════════════════════════════════════\n\nexport type { User, Impersonator, AuthenticationMethod }\n"]}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * OAuth configuration options
3
+ */
4
+ interface OAuthConfig {
5
+ /**
6
+ * Base URL for API endpoints
7
+ * @default 'https://apis.do'
8
+ */
9
+ apiUrl?: string;
10
+ /**
11
+ * Client ID for OAuth flow
12
+ */
13
+ clientId?: string;
14
+ /**
15
+ * AuthKit domain for device authorization
16
+ * @default 'login.oauth.do'
17
+ */
18
+ authKitDomain?: string;
19
+ /**
20
+ * Custom fetch implementation
21
+ */
22
+ fetch?: typeof fetch;
23
+ /**
24
+ * Custom path for token storage
25
+ * Supports ~ for home directory (e.g., '~/.studio/tokens.json')
26
+ * @default '~/.oauth.do/token'
27
+ */
28
+ storagePath?: string;
29
+ }
30
+ /**
31
+ * User information returned from auth endpoints
32
+ */
33
+ interface User {
34
+ id: string;
35
+ email?: string;
36
+ name?: string;
37
+ [key: string]: any;
38
+ }
39
+ /**
40
+ * Authentication result
41
+ */
42
+ interface AuthResult {
43
+ user: User | null;
44
+ token?: string;
45
+ }
46
+ /**
47
+ * Device authorization response
48
+ */
49
+ interface DeviceAuthorizationResponse {
50
+ device_code: string;
51
+ user_code: string;
52
+ verification_uri: string;
53
+ verification_uri_complete: string;
54
+ expires_in: number;
55
+ interval: number;
56
+ }
57
+ /**
58
+ * Token response
59
+ */
60
+ interface TokenResponse {
61
+ access_token: string;
62
+ refresh_token?: string;
63
+ token_type: string;
64
+ expires_in?: number;
65
+ user?: User;
66
+ }
67
+ /**
68
+ * Token polling error types
69
+ */
70
+ type TokenError = 'authorization_pending' | 'slow_down' | 'access_denied' | 'expired_token' | 'unknown';
71
+ /**
72
+ * Stored token data including refresh token and expiration
73
+ */
74
+ interface StoredTokenData {
75
+ accessToken: string;
76
+ refreshToken?: string;
77
+ expiresAt?: number;
78
+ }
79
+ /**
80
+ * Token storage interface
81
+ */
82
+ interface TokenStorage {
83
+ getToken(): Promise<string | null>;
84
+ setToken(token: string): Promise<void>;
85
+ removeToken(): Promise<void>;
86
+ getTokenData?(): Promise<StoredTokenData | null>;
87
+ setTokenData?(data: StoredTokenData): Promise<void>;
88
+ }
89
+
90
+ export type { AuthResult, DeviceAuthorizationResponse, OAuthConfig, StoredTokenData, TokenError, TokenResponse, TokenStorage, User };
@@ -0,0 +1,3 @@
1
+
2
+ //# sourceMappingURL=types-export.js.map
3
+ //# sourceMappingURL=types-export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"types-export.js"}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "oauth.do",
3
- "version": "0.1.14",
4
- "description": "OAuth authentication SDK and CLI for .do Platform",
3
+ "version": "0.2.0",
4
+ "description": "OAuth authentication SDK, React components, and Hono middleware for org.ai identity",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "bin": {
9
- "oauth.do": "./dist/cli.js"
9
+ "oauth.do": "./dist/cli.js",
10
+ "duckdb-auth": "./bin/duckdb-auth"
10
11
  },
11
12
  "exports": {
12
13
  ".": {
@@ -21,10 +22,27 @@
21
22
  "require": "./dist/node.js",
22
23
  "default": "./dist/node.js"
23
24
  },
25
+ "./react": {
26
+ "types": "./dist/react.d.ts",
27
+ "import": "./dist/react.js",
28
+ "require": "./dist/react.js",
29
+ "default": "./dist/react.js"
30
+ },
31
+ "./hono": {
32
+ "types": "./dist/hono.d.ts",
33
+ "import": "./dist/hono.js",
34
+ "require": "./dist/hono.js",
35
+ "default": "./dist/hono.js"
36
+ },
37
+ "./types": {
38
+ "types": "./dist/types-export.d.ts",
39
+ "import": "./dist/types-export.js"
40
+ },
24
41
  "./mdx/*": "./src/mdx/*"
25
42
  },
26
43
  "files": [
27
44
  "dist",
45
+ "bin",
28
46
  "src/mdx",
29
47
  "README.md",
30
48
  "LICENSE"
@@ -42,16 +60,19 @@
42
60
  "authentication",
43
61
  "auth",
44
62
  "login",
45
- "api-key",
63
+ "identity",
46
64
  "cli",
47
65
  "sdk",
48
- "platform",
49
- "workos"
66
+ "org-ai",
67
+ "workos",
68
+ "authkit",
69
+ "react",
70
+ "hono"
50
71
  ],
51
72
  "author": {
52
- "name": "Platform.do",
53
- "email": "npm@platform.do",
54
- "url": "https://platform.do"
73
+ "name": "org.ai",
74
+ "email": "npm@org.ai",
75
+ "url": "https://org.ai"
55
76
  },
56
77
  "license": "MIT",
57
78
  "repository": {
@@ -71,8 +92,57 @@
71
92
  "optionalDependencies": {
72
93
  "keytar": "^7.9.0"
73
94
  },
95
+ "peerDependencies": {
96
+ "@radix-ui/themes": ">=3.0.0",
97
+ "@tanstack/react-query": ">=5.0.0",
98
+ "@workos-inc/authkit-react": ">=0.5.0",
99
+ "@workos-inc/widgets": ">=1.0.0",
100
+ "hono": ">=4.0.0",
101
+ "jose": ">=5.0.0",
102
+ "react": ">=18.0.0",
103
+ "react-dom": ">=18.0.0"
104
+ },
105
+ "peerDependenciesMeta": {
106
+ "@radix-ui/themes": {
107
+ "optional": true
108
+ },
109
+ "@tanstack/react-query": {
110
+ "optional": true
111
+ },
112
+ "@workos-inc/authkit-react": {
113
+ "optional": true
114
+ },
115
+ "@workos-inc/widgets": {
116
+ "optional": true
117
+ },
118
+ "hono": {
119
+ "optional": true
120
+ },
121
+ "jose": {
122
+ "optional": true
123
+ },
124
+ "react": {
125
+ "optional": true
126
+ },
127
+ "react-dom": {
128
+ "optional": true
129
+ }
130
+ },
74
131
  "devDependencies": {
132
+ "@radix-ui/themes": "^3.0.0",
133
+ "@tanstack/react-query": "^5.0.0",
134
+ "@testing-library/jest-dom": "^6.9.1",
135
+ "@testing-library/react": "^16.3.2",
75
136
  "@types/node": "^24.10.1",
137
+ "@types/react": "^18.2.0",
138
+ "@types/react-dom": "^18.2.0",
139
+ "@workos-inc/authkit-react": "^0.16.0",
140
+ "@workos-inc/widgets": "^1.0.0",
141
+ "hono": "^4.0.0",
142
+ "jose": "^5.0.0",
143
+ "jsdom": "^27.4.0",
144
+ "react": "^18.2.0",
145
+ "react-dom": "^18.2.0",
76
146
  "tsup": "^8.0.0",
77
147
  "typescript": "^5.5.2",
78
148
  "vitest": "^2.1.8"