Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/admin-portal/admin-portal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is auto-generated by oagen. Do not edit.

import type { WorkOS } from '../workos';
import type {
PortalLinkResponse,
PortalLinkResponseWire,
} from './interfaces/portal-link-response.interface';
import type { GenerateLink } from './interfaces/generate-link.interface';
import { deserializePortalLinkResponse } from './serializers/portal-link-response.serializer';
import { serializeGenerateLink } from './serializers/generate-link.serializer';

export class AdminPortal {
constructor(private readonly workos: WorkOS) {}

/**
* Generate a Portal Link
*
* Generate a Portal Link scoped to an Organization.
* @param payload - Object containing organization.
* @returns {Promise<PortalLinkResponse>}
* @throws {BadRequestException} 400
* @throws {AuthorizationException} 403
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
* @throws {NotFoundException} 404
* @throws {UnprocessableEntityException} 422
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Update JSDoc to match current payload and error behavior.

Line 19 still says “Object containing organization,” but GenerateLink now includes additional fields (e.g., intent options/admin emails). Also, Line 22 documents AuthorizationException for 403, which is not explicitly mapped in src/workos.ts error handling. This can mislead SDK consumers.

📝 Suggested doc fix
- * `@param` payload - Object containing organization.
+ * `@param` payload - Admin Portal link generation parameters.
...
- * `@throws` {AuthorizationException} 403
+ * `@throws` {OauthException | GenericServerException} 403
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* @param payload - Object containing organization.
* @returns {Promise<PortalLinkResponse>}
* @throws {BadRequestException} 400
* @throws {AuthorizationException} 403
* @throws {NotFoundException} 404
* @throws {UnprocessableEntityException} 422
* `@param` payload - Admin Portal link generation parameters.
* `@returns` {Promise<PortalLinkResponse>}
* `@throws` {BadRequestException} 400
* `@throws` {OauthException | GenericServerException} 403
* `@throws` {NotFoundException} 404
* `@throws` {UnprocessableEntityException} 422
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/admin-portal/admin-portal.ts` around lines 19 - 24, Update the JSDoc in
src/admin-portal/admin-portal.ts for the GenerateLink function to reflect the
current payload and real error mapping: change the `@param` description from
"Object containing organization" to list the actual payload fields (e.g.,
organization, intent options, adminEmails) and their types/optional flags, and
update the `@throws` block to match the errors produced by src/workos.ts (remove
or correct the undocumented AuthorizationException 403 entry—either map it to
the actual error thrown by workos.ts or remove the 403 line if not returned;
keep BadRequestException 400, NotFoundException 404, and
UnprocessableEntityException 422 as appropriate). Ensure the JSDoc references
the GenerateLink function name so consumers see the accurate payload and
exception behavior.

*/
async generateLink(payload: GenerateLink): Promise<PortalLinkResponse> {
const { data } = await this.workos.post<PortalLinkResponseWire>(
'/portal/generate_link',
serializeGenerateLink(payload),
);
return deserializePortalLinkResponse(data);
}
}
13 changes: 13 additions & 0 deletions src/admin-portal/fixtures/generate-link.fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"return_url": "https://example.com/admin-portal/return",
"success_url": "https://example.com/admin-portal/success",
"organization": "org_01EHZNVPK3SFK441A1RGBFSHRT",
"intent": "sso",
"intent_options": {
"sso": {
"bookmark_slug": "chatgpt",
"provider_type": "GoogleSAML"
}
},
"admin_emails": ["admin@example.com"]
}
6 changes: 6 additions & 0 deletions src/admin-portal/fixtures/intent-options.fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sso": {
"bookmark_slug": "chatgpt",
"provider_type": "GoogleSAML"
}
}
3 changes: 3 additions & 0 deletions src/admin-portal/fixtures/portal-link-response.fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"link": "https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Replace secret-like token in fixture to avoid leak-scanner failures.

Line 2 uses a JWT-looking token string. Even in test fixtures, this pattern can be treated as exposed credentials and fail security checks. Use an obviously fake token value instead.

Suggested change
-  "link": "https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
+  "link": "https://setup.workos.com?token=test_admin_portal_token"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"link": "https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
"link": "https://setup.workos.com?token=test_admin_portal_token"
🧰 Tools
🪛 Betterleaks (1.1.2)

[high] 2-2: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/admin-portal/fixtures/portal-link-response.fixture.json` at line 2, The
fixture's "link" value contains a JWT-like token that triggers leak scanners;
update the value for the "link" key in portal-link-response.fixture.json to use
a clearly fake placeholder token (e.g., replace the query param value with
"REDACTED_TOKEN" or "fake-token-123") while keeping the URL structure
(https://setup.workos.com?token=...) so tests still parse the URL format but no
real/secret-looking token remains.

}
4 changes: 4 additions & 0 deletions src/admin-portal/fixtures/sso-intent-options.fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"bookmark_slug": "chatgpt",
"provider_type": "GoogleSAML"
}
41 changes: 41 additions & 0 deletions src/admin-portal/interfaces/generate-link.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file is auto-generated by oagen. Do not edit.

import type {
IntentOptions,
IntentOptionsResponse,
} from './intent-options.interface';
import type { GenerateLinkIntent } from '../../common/interfaces/generate-link-intent.interface';

export interface GenerateLink {
/** The URL to go to when an admin clicks on your logo in the Admin Portal. If not specified, the return URL configured on the [Redirects](https://dashboard.workos.com/redirects) page will be used. */
returnUrl?: string;
/** The URL to redirect the admin to when they finish setup. If not specified, the success URL configured on the [Redirects](https://dashboard.workos.com/redirects) page will be used. */
successUrl?: string;
/** An [Organization](https://workos.com/docs/reference/organization) identifier. */
organization: string;
/**
*
* The intent of the Admin Portal.
* - `sso` - Launch Admin Portal for creating SSO connections
* - `dsync` - Launch Admin Portal for creating Directory Sync connections
* - `audit_logs` - Launch Admin Portal for viewing Audit Logs
* - `log_streams` - Launch Admin Portal for creating Log Streams
* - `domain_verification` - Launch Admin Portal for Domain Verification
* - `certificate_renewal` - Launch Admin Portal for renewing SAML Certificates
* - `bring_your_own_key` - Launch Admin Portal for configuring Bring Your Own Key
*/
intent?: GenerateLinkIntent;
/** Options to configure the Admin Portal based on the intent. */
intentOptions?: IntentOptions;
/** The email addresses of the IT admins to grant access to the Admin Portal for the given organization. Accepts up to 20 emails. */
adminEmails?: string[];
}

export interface GenerateLinkResponse {
return_url?: string;
success_url?: string;
organization: string;
intent?: GenerateLinkIntent;
intent_options?: IntentOptionsResponse;
admin_emails?: string[];
}
6 changes: 6 additions & 0 deletions src/admin-portal/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This file is auto-generated by oagen. Do not edit.

export * from './generate-link.interface';
export * from './intent-options.interface';
export * from './portal-link-response.interface';
export * from './sso-intent-options.interface';
15 changes: 15 additions & 0 deletions src/admin-portal/interfaces/intent-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This file is auto-generated by oagen. Do not edit.

import type {
SSOIntentOptions,
SSOIntentOptionsResponse,
} from './sso-intent-options.interface';

export interface IntentOptions {
/** SSO-specific options for the Admin Portal. */
sso: SSOIntentOptions;
}

export interface IntentOptionsResponse {
sso: SSOIntentOptionsResponse;
}
10 changes: 10 additions & 0 deletions src/admin-portal/interfaces/portal-link-response.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is auto-generated by oagen. Do not edit.

export interface PortalLinkResponse {
/** An ephemeral link to initiate the Admin Portal. */
link: string;
}

export interface PortalLinkResponseWire {
link: string;
}
13 changes: 13 additions & 0 deletions src/admin-portal/interfaces/sso-intent-options.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file is auto-generated by oagen. Do not edit.

export interface SSOIntentOptions {
/** The bookmark slug to use for SSO. */
bookmarkSlug?: string;
/** The SSO provider type to configure. */
providerType?: 'GoogleSAML';
}

export interface SSOIntentOptionsResponse {
bookmark_slug?: string;
provider_type?: 'GoogleSAML';
}
62 changes: 62 additions & 0 deletions src/admin-portal/serializers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// This file is auto-generated by oagen. Do not edit.

import {
deserializeSSOIntentOptions,
serializeSSOIntentOptions,
} from './serializers/sso-intent-options.serializer';
import {
deserializeIntentOptions,
serializeIntentOptions,
} from './serializers/intent-options.serializer';
import {
deserializeGenerateLink,
serializeGenerateLink,
} from './serializers/generate-link.serializer';
import {
deserializePortalLinkResponse,
serializePortalLinkResponse,
} from './serializers/portal-link-response.serializer';
import type { SSOIntentOptionsResponse } from './interfaces/sso-intent-options.interface';
import type { IntentOptionsResponse } from './interfaces/intent-options.interface';
import type { GenerateLinkResponse } from './interfaces/generate-link.interface';
import type { PortalLinkResponseWire } from './interfaces/portal-link-response.interface';
import sSOIntentOptionsFixture from './fixtures/sso-intent-options.fixture.json';
import intentOptionsFixture from './fixtures/intent-options.fixture.json';
import generateLinkFixture from './fixtures/generate-link.fixture.json';
import portalLinkResponseFixture from './fixtures/portal-link-response.fixture.json';

describe('SSOIntentOptionsSerializer', () => {
it('round-trips through serialize/deserialize', () => {
const fixture = sSOIntentOptionsFixture as SSOIntentOptionsResponse;
const deserialized = deserializeSSOIntentOptions(fixture);
const reserialized = serializeSSOIntentOptions(deserialized);
expect(reserialized).toEqual(expect.objectContaining(fixture));
});
});

describe('IntentOptionsSerializer', () => {
it('round-trips through serialize/deserialize', () => {
const fixture = intentOptionsFixture as IntentOptionsResponse;
const deserialized = deserializeIntentOptions(fixture);
const reserialized = serializeIntentOptions(deserialized);
expect(reserialized).toEqual(expect.objectContaining(fixture));
});
});

describe('GenerateLinkSerializer', () => {
it('round-trips through serialize/deserialize', () => {
const fixture = generateLinkFixture as GenerateLinkResponse;
const deserialized = deserializeGenerateLink(fixture);
const reserialized = serializeGenerateLink(deserialized);
expect(reserialized).toEqual(expect.objectContaining(fixture));
});
});

describe('PortalLinkResponseSerializer', () => {
it('round-trips through serialize/deserialize', () => {
const fixture = portalLinkResponseFixture as PortalLinkResponseWire;
const deserialized = deserializePortalLinkResponse(fixture);
const reserialized = serializePortalLinkResponse(deserialized);
expect(reserialized).toEqual(expect.objectContaining(fixture));
});
});
Comment on lines +1 to +62
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No integration-level tests for AdminPortal.generateLink

The deleted src/portal/portal.spec.ts had nine HTTP-mock tests covering every intent value, error responses (400), and serialized request-body shape assertions. The new serializers.spec.ts only validates round-trip serialize/deserialize, leaving AdminPortal.generateLink (the actual HTTP call, query serialization, and new fields adminEmails / intentOptions) untested at the integration level. Consider porting the HTTP-mock tests to a new admin-portal.spec.ts, especially for the new parameters.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 24b982b — added admin-portal.spec.ts with 9 HTTP-mock integration tests covering all 7 intent values, the new intentOptions/adminEmails parameters, and error handling (400 with invalid organization). This matches the coverage from the old portal.spec.ts.

Comment on lines +28 to +62
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial

Consider table-driven tests to reduce duplication.

Current coverage is good; a parameterized pattern would make adding serializer cases simpler and keep this file smaller.

♻️ Optional refactor
+type RoundTripCase<T> = {
+  name: string;
+  fixture: T;
+  deserialize: (input: T) => any;
+  serialize: (input: any) => T;
+};
+
+const cases: RoundTripCase<any>[] = [
+  {
+    name: 'SSOIntentOptionsSerializer',
+    fixture: sSOIntentOptionsFixture as SSOIntentOptionsResponse,
+    deserialize: deserializeSSOIntentOptions,
+    serialize: serializeSSOIntentOptions,
+  },
+  {
+    name: 'IntentOptionsSerializer',
+    fixture: intentOptionsFixture as IntentOptionsResponse,
+    deserialize: deserializeIntentOptions,
+    serialize: serializeIntentOptions,
+  },
+  {
+    name: 'GenerateLinkSerializer',
+    fixture: generateLinkFixture as GenerateLinkResponse,
+    deserialize: deserializeGenerateLink,
+    serialize: serializeGenerateLink,
+  },
+  {
+    name: 'PortalLinkResponseSerializer',
+    fixture: portalLinkResponseFixture as PortalLinkResponseWire,
+    deserialize: deserializePortalLinkResponse,
+    serialize: serializePortalLinkResponse,
+  },
+];
+
+describe.each(cases)('$name', ({ fixture, deserialize, serialize }) => {
+  it('round-trips through serialize/deserialize', () => {
+    const deserialized = deserialize(fixture);
+    const reserialized = serialize(deserialized);
+    expect(reserialized).toEqual(expect.objectContaining(fixture));
+  });
+});
-
-describe('SSOIntentOptionsSerializer', () => {
-  it('round-trips through serialize/deserialize', () => {
-    const fixture = sSOIntentOptionsFixture as SSOIntentOptionsResponse;
-    const deserialized = deserializeSSOIntentOptions(fixture);
-    const reserialized = serializeSSOIntentOptions(deserialized);
-    expect(reserialized).toEqual(expect.objectContaining(fixture));
-  });
-});
-
-... repeated blocks ...
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/admin-portal/serializers.spec.ts` around lines 28 - 62, Replace the four
near-identical describe/it blocks with a single table-driven test: create an
array of cases each containing a name (e.g., "SSOIntentOptions",
"IntentOptions", "GenerateLink", "PortalLinkResponse"), the corresponding
fixture variable (sSOIntentOptionsFixture, intentOptionsFixture,
generateLinkFixture, portalLinkResponseFixture) and the pair of functions
(deserializeSSOIntentOptions/serializeSSOIntentOptions,
deserializeIntentOptions/serializeIntentOptions,
deserializeGenerateLink/serializeGenerateLink,
deserializePortalLinkResponse/serializePortalLinkResponse). Iterate the cases
with test.each or a forEach and for each case call the deserialize function with
the fixture, reserialize it with the matching serialize function, and assert
expect(reserialized).toEqual(expect.objectContaining(fixture)); this removes
duplication while keeping the same assertions and using the existing fixture and
serializer function names to locate code.

38 changes: 38 additions & 0 deletions src/admin-portal/serializers/generate-link.serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This file is auto-generated by oagen. Do not edit.

import type {
GenerateLink,
GenerateLinkResponse,
} from '../interfaces/generate-link.interface';
import {
deserializeIntentOptions,
serializeIntentOptions,
} from './intent-options.serializer';

export const deserializeGenerateLink = (
response: GenerateLinkResponse,
): GenerateLink => ({
returnUrl: response.return_url,
successUrl: response.success_url,
organization: response.organization,
intent: response.intent,
intentOptions:
response.intent_options != null
? deserializeIntentOptions(response.intent_options)
: undefined,
adminEmails: response.admin_emails,
});

export const serializeGenerateLink = (
model: GenerateLink,
): GenerateLinkResponse => ({
return_url: model.returnUrl,
success_url: model.successUrl,
organization: model.organization,
intent: model.intent,
intent_options:
model.intentOptions != null
? serializeIntentOptions(model.intentOptions)
: undefined,
admin_emails: model.adminEmails,
});
22 changes: 22 additions & 0 deletions src/admin-portal/serializers/intent-options.serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This file is auto-generated by oagen. Do not edit.

import type {
IntentOptions,
IntentOptionsResponse,
} from '../interfaces/intent-options.interface';
import {
deserializeSSOIntentOptions,
serializeSSOIntentOptions,
} from './sso-intent-options.serializer';

export const deserializeIntentOptions = (
response: IntentOptionsResponse,
): IntentOptions => ({
sso: deserializeSSOIntentOptions(response.sso),
});

export const serializeIntentOptions = (
model: IntentOptions,
): IntentOptionsResponse => ({
sso: serializeSSOIntentOptions(model.sso),
});
18 changes: 18 additions & 0 deletions src/admin-portal/serializers/portal-link-response.serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This file is auto-generated by oagen. Do not edit.

import type {
PortalLinkResponse,
PortalLinkResponseWire,
} from '../interfaces/portal-link-response.interface';

export const deserializePortalLinkResponse = (
response: PortalLinkResponseWire,
): PortalLinkResponse => ({
link: response.link,
});

export const serializePortalLinkResponse = (
model: PortalLinkResponse,
): PortalLinkResponseWire => ({
link: model.link,
});
20 changes: 20 additions & 0 deletions src/admin-portal/serializers/sso-intent-options.serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This file is auto-generated by oagen. Do not edit.

import type {
SSOIntentOptions,
SSOIntentOptionsResponse,
} from '../interfaces/sso-intent-options.interface';

export const deserializeSSOIntentOptions = (
response: SSOIntentOptionsResponse,
): SSOIntentOptions => ({
bookmarkSlug: response.bookmark_slug,
providerType: response.provider_type,
});

export const serializeSSOIntentOptions = (
model: SSOIntentOptions,
): SSOIntentOptionsResponse => ({
bookmark_slug: model.bookmarkSlug,
provider_type: model.providerType,
});
10 changes: 10 additions & 0 deletions src/common/interfaces/generate-link-intent.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is auto-generated by oagen. Do not edit.

export type GenerateLinkIntent =
| 'sso'
| 'dsync'
| 'audit_logs'
| 'log_streams'
| 'domain_verification'
| 'certificate_renewal'
| 'bring_your_own_key';
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// This file is auto-generated by oagen. Do not edit.

import { SubtleCryptoProvider } from './common/crypto/subtle-crypto-provider';
import { CryptoProvider } from './common/crypto/crypto-provider';

Expand All @@ -23,7 +25,7 @@ export { FeatureFlagsRuntimeClient } from './feature-flags/runtime-client';
export * from './organizations/interfaces';
export * from './organization-domains/interfaces';
export * from './passwordless/interfaces';
export * from './portal/interfaces';
export * from './admin-portal/interfaces';
export * from './roles/interfaces';
export * from './sso/interfaces';
export * from './user-management/interfaces';
Expand Down
2 changes: 1 addition & 1 deletion src/index.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export * from './events/interfaces';
export * from './organizations/interfaces';
export * from './organization-domains/interfaces';
export * from './passwordless/interfaces';
export * from './portal/interfaces';
export * from './admin-portal/interfaces';
export * from './sso/interfaces';
export * from './user-management/interfaces';
export * from './roles/interfaces';
Expand Down
1 change: 0 additions & 1 deletion src/portal/fixtures/generate-link-invalid.json

This file was deleted.

1 change: 0 additions & 1 deletion src/portal/fixtures/generate-link.json

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/portal/interfaces/index.ts

This file was deleted.

Loading
Loading