Skip to content
Open
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
46 changes: 46 additions & 0 deletions src/admin-portal/admin-portal.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This file is auto-generated by oagen. Do not edit.

import fetch from 'jest-fetch-mock';
import {
fetchOnce,
fetchURL,
fetchMethod,
fetchBody,
testUnauthorized,
} from '../common/utils/test-utils';
import { WorkOS } from '../workos';

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

const workos = new WorkOS('sk_test_Sz3IQjepeSWaI4cMS4ms4sMuU');

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

describe('generatePortalLink', () => {
it('sends the correct request and returns result', async () => {
fetchOnce(portalLinkResponseFixture);

const result = await workos.adminPortal.generatePortalLink({
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...',
);
});

testUnauthorized(() =>
workos.adminPortal.generatePortalLink({
organization: 'test_organization',
}),
);
});
});
32 changes: 32 additions & 0 deletions src/admin-portal/admin-portal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 {PortalLinkResponse}
* @throws {BadRequestException} 400
* @throws {NotFoundException} 404
* @throws {UnprocessableEntityException} 422
*/
async generatePortalLink(payload: GenerateLink): Promise<PortalLinkResponse> {
const { data } = await this.workos.post<PortalLinkResponseWire>(
'/portal/generate_link',
serializeGenerateLink(payload),
);
return deserializePortalLinkResponse(data);
}
}
12 changes: 12 additions & 0 deletions src/admin-portal/fixtures/generate-link.fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"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"
}
}
}
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..."
}
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"
}
38 changes: 38 additions & 0 deletions src/admin-portal/interfaces/generate-link.interface.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 {
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;
}

export interface GenerateLinkResponse {
return_url?: string;
success_url?: string;
organization: string;
intent?: GenerateLinkIntent;
intent_options?: IntentOptionsResponse;
}
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';
}
36 changes: 36 additions & 0 deletions src/admin-portal/serializers/generate-link.serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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,
});

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,
});
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,
});
5 changes: 5 additions & 0 deletions src/authorization/authorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export class Authorization {
);
}

/** @deprecated Use `workos.permissions.create()` instead. */
async createPermission(
options: CreatePermissionOptions,
): Promise<Permission> {
Expand All @@ -240,6 +241,7 @@ export class Authorization {
return deserializePermission(data);
}

/** @deprecated Use `workos.permissions.list()` instead. */
async listPermissions(
options?: ListPermissionsOptions,
): Promise<PermissionList> {
Expand All @@ -257,13 +259,15 @@ export class Authorization {
};
}

/** @deprecated Use `workos.permissions.find()` instead. */
async getPermission(slug: string): Promise<Permission> {
const { data } = await this.workos.get<PermissionResponse>(
`/authorization/permissions/${slug}`,
);
return deserializePermission(data);
}

/** @deprecated Use `workos.permissions.update()` instead. */
async updatePermission(
slug: string,
options: UpdatePermissionOptions,
Expand All @@ -275,6 +279,7 @@ export class Authorization {
return deserializePermission(data);
}

/** @deprecated Use `workos.permissions.delete()` instead. */
async deletePermission(slug: string): Promise<void> {
await this.workos.delete(`/authorization/permissions/${slug}`);
}
Expand Down
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 UpdateOrganizationRole {
/** A descriptive name for the role. */
name?: string;
/** An optional description of the role's purpose. */
description?: string | null;
}

export interface UpdateOrganizationRoleResponse {
name?: string;
description?: string | null;
}
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 {
UpdateOrganizationRole,
UpdateOrganizationRoleResponse,
} from '../interfaces/update-organization-role.interface';

export const deserializeUpdateOrganizationRole = (
response: UpdateOrganizationRoleResponse,
): UpdateOrganizationRole => ({
name: response.name,
description: response.description ?? null,
});

export const serializeUpdateOrganizationRole = (
model: UpdateOrganizationRole,
): UpdateOrganizationRoleResponse => ({
name: model.name,
description: model.description ?? null,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"issuer": "WorkOS",
"user": "user@example.com"
}
13 changes: 13 additions & 0 deletions src/common/interfaces/authentication-factor-totp-2.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 AuthenticationFactorTotp2 {
/** Your application or company name displayed in the user's authenticator app. Defaults to your WorkOS team name. */
issuer: string;
/** The user's account name displayed in their authenticator app. Defaults to the user's email. */
user: string;
}

export interface AuthenticationFactorTotp2Response {
issuer: string;
user: string;
}
Loading
Loading