Skip to content

Commit

Permalink
feat(console): feat add SAML application creation (#6857)
Browse files Browse the repository at this point in the history
feat(console): feat add SAML appliction creation

feat add SAML application creation
  • Loading branch information
simeng-li authored Dec 5, 2024
1 parent d184223 commit c6dc935
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 11 deletions.
26 changes: 18 additions & 8 deletions packages/console/src/assets/docs/guides/generate-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const data = await Promise.all(
return;
}

const logo = ['logo.webp', 'logo.svg', 'logo.png'].find((logo) => existsSync(`${directory}/${logo}`));
const logo = ['logo.webp', 'logo.svg', 'logo.png'].find((logo) =>
existsSync(`${directory}/${logo}`)
);
const darkLogo = ['logo-dark.webp', 'logo-dark.svg', 'logo-dark.png'].find((logo) =>
existsSync(`${directory}/${logo}`)
);
Expand Down Expand Up @@ -50,7 +52,7 @@ const filename = 'index.tsx';
await fs.writeFile(
filename,
`/* eslint-disable max-lines */
// This is a generated file, don't update manually.\n\nimport { lazy } from 'react';\n\nimport { type Guide } from './types';\n`
// This is a generated file, don't update manually.\n\nimport { safeLazy } from 'react-safe-lazy';\n\nimport { type Guide } from './types';\n`
);

for (const { name, logo, darkLogo } of metadata) {
Expand All @@ -64,7 +66,10 @@ for (const { name, logo, darkLogo } of metadata) {

if (darkLogo && !darkLogo.endsWith('.svg')) {
// eslint-disable-next-line no-await-in-loop
await fs.appendFile(filename, `import ${camelCase(name)}LogoDark from './${name}/${darkLogo}';\n`);
await fs.appendFile(
filename,
`import ${camelCase(name)}LogoDark from './${name}/${darkLogo}';\n`
);
}
}

Expand All @@ -73,8 +78,10 @@ await fs.appendFile(filename, 'export const guides: Readonly<Guide[]> = Object.f

const getLogo = ({ name, logo, isDark }) => {
if (!logo) return 'undefined';
if (logo.endsWith('.svg')) return `lazy(async () => import('./${name}/${logo}?react'))`;
return `({ className }: { readonly className?: string }) => <img src={${camelCase(name)}Logo${isDark ? 'Dark' : ''}} alt="${name}" className={className} />`;
if (logo.endsWith('.svg')) return `safeLazy(async () => import('./${name}/${logo}?react'))`;
return `({ className }: { readonly className?: string }) => <img src={${camelCase(name)}Logo${
isDark ? 'Dark' : ''
}} alt="${name}" className={className} />`;
};

for (const { name, logo, darkLogo, order } of metadata) {
Expand All @@ -87,11 +94,14 @@ for (const { name, logo, darkLogo, order } of metadata) {
id: '${name}',
Logo: ${getLogo({ name, logo })},
DarkLogo: ${getLogo({ name, logo: darkLogo, isDark: true })},
Component: lazy(async () => import('./${name}/README.mdx')),
Component: safeLazy(async () => import('./${name}/README.mdx')),
metadata: ${camelCase(name)},
},`
);
}

await fs.appendFile(filename, `]);
/* eslint-enable max-lines */\n`);
await fs.appendFile(
filename,
`]);
/* eslint-enable max-lines */\n`
);
10 changes: 10 additions & 0 deletions packages/console/src/assets/docs/guides/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable max-lines */
// This is a generated file, don't update manually.

import { safeLazy } from 'react-safe-lazy';

import apiExpress from './api-express/index';
Expand All @@ -12,6 +13,7 @@ import nativeExpo from './native-expo/index';
import nativeFlutter from './native-flutter/index';
import nativeIosSwift from './native-ios-swift/index';
import protectedApp from './protected-app/index';
import samlIdp from './saml-idp/index';
import spaAngular from './spa-angular/index';
import spaChromeExtension from './spa-chrome-extension/index';
import spaReact from './spa-react/index';
Expand Down Expand Up @@ -321,6 +323,14 @@ export const guides: Readonly<Guide[]> = Object.freeze([
Component: safeLazy(async () => import('./api-spring-boot/README.mdx')),
metadata: apiSpringBoot,
},
{
order: Number.POSITIVE_INFINITY,
id: 'saml-idp',
Logo: safeLazy(async () => import('./saml-idp/logo.svg?react')),
DarkLogo: undefined,
Component: safeLazy(async () => import('./saml-idp/README.mdx')),
metadata: samlIdp,
},
{
order: Number.POSITIVE_INFINITY,
id: 'third-party-oidc',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Place holder for SAML IdP guide
15 changes: 15 additions & 0 deletions packages/console/src/assets/docs/guides/saml-idp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApplicationType } from '@logto/schemas';

import { type GuideMetadata } from '../types';

const metadata = Object.freeze({
name: 'SAML',
description: 'Use Logto as a SAML identity provider (IdP) for your application.',
target: ApplicationType.SAML,
isThirdParty: true,
skipGuideAfterCreation: true,
isCloud: true,
isDevFeature: true,
} satisfies GuideMetadata);

export default metadata;
6 changes: 6 additions & 0 deletions packages/console/src/assets/docs/guides/saml-idp/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/console/src/assets/docs/guides/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export type GuideMetadata = {
title: string;
url: URL;
}>;
/** Whether the guide is a development feature, that needs to be hidden from the production environment. */
isDevFeature?: boolean;
};

/** The guide instance to build in the console. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Modal from 'react-modal';
import { useSWRConfig } from 'swr';

import { GtagConversionId, reportConversion } from '@/components/Conversion/utils';
import { isDevFeaturesEnabled } from '@/consts/env';
import { SubscriptionDataContext } from '@/contexts/SubscriptionDataProvider';
import DynamicT from '@/ds-components/DynamicT';
import FormField from '@/ds-components/FormField';
Expand Down Expand Up @@ -91,7 +92,13 @@ function CreateForm({
return;
}

const createdApp = await api.post('api/applications', { json: data }).json<Application>();
const appCreationEndpoint =
// TODO: @darcy remove this after the SAML is implemented
isDevFeaturesEnabled && data.type === ApplicationType.SAML
? 'api/saml-applications'
: 'api/applications';

const createdApp = await api.post(appCreationEndpoint, { json: data }).json<Application>();

// Report the conversion event after the application is created. Note that the conversion
// should be set as count once since this will be reported multiple times.
Expand Down
5 changes: 3 additions & 2 deletions packages/console/src/components/Guide/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useCallback, useMemo } from 'react';

import { guides } from '@/assets/docs/guides';
import { type Guide } from '@/assets/docs/guides/types';
import { isCloud as isCloudEnv } from '@/consts/env';
import { isCloud as isCloudEnv, isDevFeaturesEnabled } from '@/consts/env';
import {
thirdPartyAppCategory,
type AppGuideCategory,
Expand Down Expand Up @@ -37,7 +37,8 @@ export const useAppGuideMetadata = (): {
const appGuides = useMemo(
() =>
guides.filter(
({ metadata: { target, isCloud } }) => target !== 'API' && (isCloudEnv || !isCloud)
({ metadata: { target, isCloud, isDevFeature } }) =>
target !== 'API' && (isCloudEnv || !isCloud) && (isDevFeaturesEnabled || !isDevFeature)
),
[]
);
Expand Down

0 comments on commit c6dc935

Please sign in to comment.