Skip to content

Commit 8a0e0aa

Browse files
committed
remove class wrapper for client interface
1 parent d91fd6a commit 8a0e0aa

File tree

14 files changed

+93
-318
lines changed

14 files changed

+93
-318
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@
103103
"require": "./lib/cjs/index.cjs",
104104
"default": "./lib/esm/index.js"
105105
},
106-
"./public": {
106+
"./client": {
107107
"types": {
108-
"require": "./lib/cjs/index.public.d.cts",
109-
"import": "./lib/esm/index.public.d.ts"
108+
"require": "./lib/cjs/index.client.d.cts",
109+
"import": "./lib/esm/index.client.d.ts"
110110
},
111-
"import": "./lib/esm/index.public.js",
112-
"require": "./lib/cjs/index.public.cjs",
113-
"default": "./lib/esm/index.public.js"
111+
"import": "./lib/esm/index.client.js",
112+
"require": "./lib/cjs/index.client.cjs",
113+
"default": "./lib/esm/index.client.js"
114114
},
115115
"./worker": {
116116
"types": {
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**
2-
* Public methods that can be safely used in without an API key.
2+
* Client methods that can be used without a WorkOS API key.
3+
* These are OAuth client operations suitable for PKCE flows.
34
*/
45

5-
// User Management public methods and types
6+
// User Management client methods and types
67
export * as userManagement from './user-management';
78

8-
// SSO public methods and types
9+
// SSO client methods and types
910
export * as sso from './sso';
1011

1112
// Re-export specific types for convenience
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface SSOAuthorizationURLOptions {
1515

1616
/**
1717
* Generates the authorization URL for SSO authentication.
18-
* This method is safe to use in browser environments as it doesn't require an API key.
18+
* Does not require an API key, suitable for OAuth client operations.
1919
*
2020
* @param options - SSO authorization URL options
2121
* @returns The authorization URL as a string
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { toQueryString } from './utils';
22

3-
// Re-export necessary interfaces for public use
3+
// Re-export necessary interfaces for client use
44
export interface AuthorizationURLOptions {
55
clientId: string;
66
codeChallenge?: string;
@@ -29,8 +29,8 @@ export interface LogoutURLOptions {
2929
}
3030

3131
/**
32-
* Generates the authorization URL for user authentication.
33-
* This method is safe to use in browser environments as it doesn't require an API key.
32+
* Generates the authorization URL for OAuth client authentication.
33+
* Suitable for PKCE flows and other OAuth client operations that don't require an API key.
3434
*
3535
* @param options - Authorization URL options
3636
* @returns The authorization URL as a string
@@ -128,7 +128,7 @@ export function getLogoutUrl(
128128

129129
/**
130130
* Gets the JWKS (JSON Web Key Set) URL for a given client ID.
131-
* This method is safe to use in browser environments as it doesn't require an API key.
131+
* Does not require an API key, returns the public JWKS endpoint.
132132
*
133133
* @param clientId - The WorkOS client ID
134134
* @param baseURL - Optional base URL for the API (defaults to https://api.workos.com)
@@ -140,7 +140,7 @@ export function getJwksUrl(
140140
baseURL = 'https://api.workos.com',
141141
): string {
142142
if (!clientId) {
143-
throw TypeError('clientId must be a valid clientId');
143+
throw new TypeError('clientId must be a valid clientId');
144144
}
145145

146146
return `${baseURL}/sso/jwks/${clientId}`;
File renamed without changes.

src/index.client.spec.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { userManagement, sso } from './index.client';
2+
3+
describe('Client Exports', () => {
4+
describe('userManagement exports', () => {
5+
it('should generate authorization URLs correctly', () => {
6+
const url = userManagement.getAuthorizationUrl({
7+
clientId: 'client_123',
8+
redirectUri: 'https://example.com/callback',
9+
provider: 'authkit',
10+
});
11+
12+
expect(url).toContain('client_id=client_123');
13+
expect(url).toContain(
14+
'redirect_uri=https%3A%2F%2Fexample.com%2Fcallback',
15+
);
16+
expect(url).toContain('provider=authkit');
17+
});
18+
19+
it('should generate logout URLs correctly', () => {
20+
const url = userManagement.getLogoutUrl({
21+
sessionId: 'session_123',
22+
returnTo: 'https://example.com',
23+
});
24+
25+
expect(url).toContain('session_id=session_123');
26+
expect(url).toContain('return_to=https%3A%2F%2Fexample.com');
27+
});
28+
29+
it('should generate JWKS URLs correctly', () => {
30+
const url = userManagement.getJwksUrl('client_123');
31+
expect(url).toBe('https://api.workos.com/sso/jwks/client_123');
32+
});
33+
});
34+
35+
describe('sso exports', () => {
36+
it('should generate SSO authorization URLs correctly', () => {
37+
const url = sso.getAuthorizationUrl({
38+
clientId: 'client_123',
39+
redirectUri: 'https://example.com/callback',
40+
provider: 'GoogleOAuth',
41+
});
42+
43+
expect(url).toContain('client_id=client_123');
44+
expect(url).toContain('provider=GoogleOAuth');
45+
});
46+
});
47+
});

src/index.client.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Client methods that can be used without a WorkOS API key.
3+
* These are OAuth client operations and URL builders suitable for PKCE flows.
4+
*/
5+
6+
// Export client methods directly - this is the recommended approach
7+
export * as userManagement from './client/user-management';
8+
export * as sso from './client/sso';
9+
10+
// Re-export types for convenience
11+
export type {
12+
AuthorizationURLOptions as UserManagementAuthorizationURLOptions,
13+
LogoutURLOptions,
14+
} from './client/user-management';
15+
16+
export type { SSOAuthorizationURLOptions } from './client/sso';
17+
18+
// Note: If you need authenticateWithCodeAndVerifier, use the full WorkOS SDK
19+
// as it requires server-side API key authentication

src/index.public.spec.ts

Lines changed: 0 additions & 153 deletions
This file was deleted.

0 commit comments

Comments
 (0)