Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
23 changes: 22 additions & 1 deletion .oagen-manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
{
"version": 2,
"language": "node",
"generatedAt": "2026-06-01T17:59:24.986Z",
"generatedAt": "2026-06-17T01:23:51.028Z",
"files": [
"src/admin-portal/admin-portal.spec.ts",
"src/admin-portal/admin-portal.ts",
"src/admin-portal/fixtures/domain-verification-intent-options.json",
"src/admin-portal/fixtures/generate-link.json",
"src/admin-portal/fixtures/intent-options.json",
"src/admin-portal/fixtures/portal-link-response.json",
"src/admin-portal/fixtures/sso-intent-options.json",
"src/admin-portal/interfaces/domain-verification-intent-options.interface.ts",
"src/admin-portal/interfaces/generate-link-intent.interface.ts",
"src/admin-portal/interfaces/generate-link.interface.ts",
"src/admin-portal/interfaces/index.ts",
"src/admin-portal/interfaces/intent-options.interface.ts",
"src/admin-portal/interfaces/portal-link-response.interface.ts",
"src/admin-portal/interfaces/sso-intent-options.interface.ts",
"src/admin-portal/serializers.spec.ts",
"src/admin-portal/serializers/domain-verification-intent-options.serializer.ts",
"src/admin-portal/serializers/generate-link.serializer.ts",
"src/admin-portal/serializers/index.ts",
"src/admin-portal/serializers/intent-options.serializer.ts",
"src/admin-portal/serializers/portal-link-response.serializer.ts",
"src/admin-portal/serializers/sso-intent-options.serializer.ts",
"src/api-keys/interfaces/create-validation-options.interface.ts",
"src/api-keys/interfaces/delete-api-key-options.interface.ts",
"src/connect/connect.spec.ts",
Expand Down
259 changes: 27 additions & 232 deletions src/admin-portal/admin-portal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,244 +1,39 @@
// This file is auto-generated by oagen. Do not edit.

import fetch from 'jest-fetch-mock';
import { fetchBody, fetchOnce } from '../common/utils/test-utils';
import {
fetchOnce,
fetchURL,
fetchMethod,
fetchBody,
} from '../common/utils/test-utils';
import { WorkOS } from '../workos';
import generateLinkInvalid from './fixtures/generate-link-invalid.json';
import portalLinkResponse from './fixtures/portal-link-response.json';
import { GenerateLinkIntent } from '../common/interfaces';

import portalLinkResponseFixture from './fixtures/portal-link-response.json';

const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');

describe('AdminPortal', () => {
beforeEach(() => fetch.resetMocks());

describe('generateLink', () => {
describe('with a valid organization', () => {
describe('with the sso intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.SSO,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the domain_verification intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.DomainVerification,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.DomainVerification,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the dsync intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.DSync,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.DSync,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the `audit_logs` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.AuditLogs,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.AuditLogs,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with the `log_streams` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.LogStreams,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.LogStreams,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});
describe('with the `certificate_renewal` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.CertificateRenewal,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.CertificateRenewal,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});
describe('with the `bring_your_own_key` intent', () => {
it('returns an Admin Portal link', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.BringYourOwnKey,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
});

expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.BringYourOwnKey,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});

describe('with intentOptions and adminEmails', () => {
it('serializes the new parameters correctly', async () => {
fetchOnce(portalLinkResponse, { status: 201 });

const { link } = await workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
returnUrl: 'https://www.example.com',
intentOptions: {
sso: {
bookmarkSlug: 'chatgpt',
providerType: 'GoogleSAML',
},
},
adminEmails: ['admin@example.com'],
});

expect(fetchBody()).toEqual({
intent: 'sso',
organization: 'org_01EHQMYV6MBK39QC5PZXHY59C3',
return_url: 'https://www.example.com',
intent_options: {
sso: {
bookmark_slug: 'chatgpt',
provider_type: 'GoogleSAML',
},
},
admin_emails: ['admin@example.com'],
});
expect(link).toEqual(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});
});

describe('with an invalid organization', () => {
it('throws an error', async () => {
fetchOnce(generateLinkInvalid, {
status: 400,
headers: { 'X-Request-ID': 'a-request-id' },
});

await expect(
workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
returnUrl: 'https://www.example.com',
}),
).rejects.toThrow(
'Could not find an organization with the id, bogus-id.',
);
expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
return_url: 'https://www.example.com',
});
});
});

describe('with an invalid organization', () => {
it('throws an error', async () => {
fetchOnce(generateLinkInvalid, {
status: 400,
headers: { 'X-Request-ID': 'a-request-id' },
});

await expect(
workos.adminPortal.generateLink({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
returnUrl: 'https://www.example.com',
}),
).rejects.toThrow(
'Could not find an organization with the id, bogus-id.',
);
expect(fetchBody()).toEqual({
intent: GenerateLinkIntent.SSO,
organization: 'bogus-id',
return_url: 'https://www.example.com',
});
});
it('sends the correct request and returns result', async () => {
fetchOnce(portalLinkResponseFixture);

const result = await workos.adminPortal.generateLink({
organization: 'test_organization',
});

expect(fetchMethod()).toBe('POST');
expect(new URL(String(fetchURL())).pathname).toBe(
'/portal/generate_link',
);
expect(fetchBody()).toEqual(
expect.objectContaining({ organization: 'test_organization' }),
);
expect(result.link).toBe(
'https://setup.workos.com?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
);
});
});
});
80 changes: 38 additions & 42 deletions src/admin-portal/admin-portal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// This file is auto-generated by oagen. Do not edit.

import { WorkOS } from '../workos';
import { GenerateLinkIntent } from '../common/interfaces';
import type { WorkOS } from '../workos';
import type { GenerateLink } from './interfaces/generate-link.interface';
import type {
PortalLinkResponse,
PortalLinkResponseWire,
} from './interfaces/portal-link-response.interface';
import type { GenerateLinkResponse } 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) {}
Expand All @@ -10,49 +17,38 @@ export class AdminPortal {
* Generate a Portal Link
*
* Generate a Portal Link scoped to an Organization.
* @param payload - Object containing organization.
* @returns {Promise<{ link: string; }>}
* @param options - Object containing organization.
* @param options.returnUrl - 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.
* @example "https://example.com/admin-portal/return"
* @param options.successUrl - 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.
* @example "https://example.com/admin-portal/success"
* @param options.organization - An [Organization](https://workos.com/docs/reference/organization) identifier.
* @example "org_01EHZNVPK3SFK441A1RGBFSHRT"
* @param options.intent -
* 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
* @example "sso"
* @param options.intentOptions - Options to configure the Admin Portal based on the intent.
* @param options.itContactEmails - The email addresses of the IT contacts to grant access to the Admin Portal for the given organization. Accepts up to 20 emails.
* @example ["it-contact@example.com"]
* @returns {Promise<PortalLinkResponse>}
* @throws {BadRequestException} 400
* @throws 403 response from the API.
* @throws {AuthorizationException} 403
* @throws {NotFoundException} 404
* @throws {UnprocessableEntityException} 422
*/
async generateLink({
intent,
organization,
returnUrl,
successUrl,
intentOptions,
adminEmails,
}: {
intent?: GenerateLinkIntent;
organization: string;
returnUrl?: string;
successUrl?: string;
intentOptions?: {
sso: {
bookmarkSlug?: string;
providerType?: string;
};
};
adminEmails?: string[];
}): Promise<{ link: string }> {
const { data } = await this.workos.post('/portal/generate_link', {
intent,
organization,
return_url: returnUrl,
success_url: successUrl,
intent_options: intentOptions
? {
sso: {
bookmark_slug: intentOptions.sso.bookmarkSlug,
provider_type: intentOptions.sso.providerType,
},
}
: undefined,
admin_emails: adminEmails,
});

return data;
async generateLink(options: GenerateLink): Promise<PortalLinkResponse> {
const payload = options;
const { data } = await this.workos.post<
PortalLinkResponseWire,
GenerateLinkResponse
>('/portal/generate_link', serializeGenerateLink(payload));
Comment on lines +46 to +51

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 The intermediate const payload = options; assignment adds no value — options can be passed directly to serializeGenerateLink.

Suggested change
async generateLink(options: GenerateLink): Promise<PortalLinkResponse> {
const payload = options;
const { data } = await this.workos.post<
PortalLinkResponseWire,
GenerateLinkResponse
>('/portal/generate_link', serializeGenerateLink(payload));
async generateLink(options: GenerateLink): Promise<PortalLinkResponse> {
const { data } = await this.workos.post<
PortalLinkResponseWire,
GenerateLinkResponse
>('/portal/generate_link', serializeGenerateLink(options));

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

return deserializePortalLinkResponse(data);
}
}
Loading