Skip to content

Commit

Permalink
Add support for self-service profiles (#989)
Browse files Browse the repository at this point in the history
* ss-sso files added

* support dum,deploy for  self-service-sso

* unit test added yaml, directory

* added e2e recordings

* lint fix
  • Loading branch information
kushalshit27 authored Nov 28, 2024
1 parent 5ff0727 commit a13e794
Show file tree
Hide file tree
Showing 21 changed files with 14,898 additions and 3,893 deletions.
490 changes: 104 additions & 386 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"homepage": "https://github.com/auth0/auth0-deploy-cli#readme",
"dependencies": {
"ajv": "^6.12.6",
"auth0": "^4.13.0",
"auth0": "^4.14.0",
"dot-prop": "^5.2.0",
"fs-extra": "^10.1.0",
"global-agent": "^2.1.12",
Expand Down Expand Up @@ -71,7 +71,7 @@
"sinon": "^13.0.2",
"sinon-chai": "^3.7.0",
"ts-mocha": "^10.0.0",
"typescript": "^5.6.3",
"typescript": "^5.7.2",
"zlib": "^1.0.5"
},
"engines": {
Expand Down
2 changes: 2 additions & 0 deletions src/context/directory/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import flowVaultConnections from './flowVaultConnections';

import DirectoryContext from '..';
import { AssetTypes, Asset } from '../../../types';
import selfServiceProfiles from './selfServiceProfiles';

export type DirectoryHandler<T> = {
dump: (context: DirectoryContext) => void;
Expand Down Expand Up @@ -72,6 +73,7 @@ const directoryHandlers: {
forms,
flows,
flowVaultConnections,
selfServiceProfiles,
};

export default directoryHandlers;
72 changes: 72 additions & 0 deletions src/context/directory/handlers/selfServiceProfiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import path from 'path';
import fs from 'fs-extra';
import { constants } from '../../../tools';
import log from '../../../logger';

import { dumpJSON, existsMustBeDir, getFiles, loadJSON, sanitize } from '../../../utils';
import { DirectoryHandler } from '.';
import DirectoryContext from '..';
import { ParsedAsset } from '../../../types';
import { SsProfileWithCustomText } from '../../../tools/auth0/handlers/selfServiceProfiles';

type ParsedSelfServiceProfiles = ParsedAsset<
'selfServiceProfiles',
Partial<SsProfileWithCustomText>[]
>;

function parse(context: DirectoryContext): ParsedSelfServiceProfiles {
const selfServiceProfilesFolder = path.join(
context.filePath,
constants.SELF_SERVICE_PROFILE_DIRECTORY
);
if (!existsMustBeDir(selfServiceProfilesFolder)) return { selfServiceProfiles: null }; // Skip

const files = getFiles(selfServiceProfilesFolder, ['.json']);

const selfServiceProfiles = files.map((f) => {
const ssProfiles = {
...loadJSON(f, {
mappings: context.mappings,
disableKeywordReplacement: context.disableKeywordReplacement,
}),
};
return ssProfiles;
});

return {
selfServiceProfiles,
};
}

async function dump(context: DirectoryContext): Promise<void> {
const { selfServiceProfiles } = context.assets;
if (!selfServiceProfiles) return;

const selfServiceProfilesFolder = path.join(
context.filePath,
constants.SELF_SERVICE_PROFILE_DIRECTORY
);
fs.ensureDirSync(selfServiceProfilesFolder);

selfServiceProfiles.forEach((profile) => {
const ssProfileFile = path.join(selfServiceProfilesFolder, sanitize(`${profile.name}.json`));
log.info(`Writing ${ssProfileFile}`);

if ('created_at' in profile) {
delete profile.created_at;
}

if ('updated_at' in profile) {
delete profile.updated_at;
}

dumpJSON(ssProfileFile, profile);
});
}

const emailProviderHandler: DirectoryHandler<ParsedSelfServiceProfiles> = {
parse,
dump,
};

export default emailProviderHandler;
2 changes: 2 additions & 0 deletions src/context/yaml/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import flowVaultConnections from './flowVaultConnections';

import YAMLContext from '..';
import { AssetTypes } from '../../../types';
import selfServiceProfiles from './selfServiceProfiles';

export type YAMLHandler<T> = {
dump: (context: YAMLContext) => Promise<T>;
Expand Down Expand Up @@ -70,6 +71,7 @@ const yamlHandlers: { [key in AssetTypes]: YAMLHandler<{ [key: string]: unknown
forms,
flows,
flowVaultConnections,
selfServiceProfiles,
};

export default yamlHandlers;
49 changes: 49 additions & 0 deletions src/context/yaml/handlers/selfServiceProfiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { YAMLHandler } from '.';
import YAMLContext from '..';
import { ParsedAsset } from '../../../types';
import { SsProfileWithCustomText } from '../../../tools/auth0/handlers/selfServiceProfiles';

type ParsedSelfServiceProfiles = ParsedAsset<
'selfServiceProfiles',
Partial<SsProfileWithCustomText>[]
>;

async function parse(context: YAMLContext): Promise<ParsedSelfServiceProfiles> {
const { selfServiceProfiles } = context.assets;

if (!selfServiceProfiles) return { selfServiceProfiles: null };

return {
selfServiceProfiles,
};
}

async function dump(context: YAMLContext): Promise<ParsedSelfServiceProfiles> {
let { selfServiceProfiles } = context.assets;
if (!selfServiceProfiles) return { selfServiceProfiles: null };

selfServiceProfiles = selfServiceProfiles.map((profile) => {
if ('created_at' in profile) {
delete profile.created_at;
}

if ('updated_at' in profile) {
delete profile.updated_at;
}

return {
...profile,
};
});

return {
selfServiceProfiles,
};
}

const selfServiceProfileHandler: YAMLHandler<ParsedSelfServiceProfiles> = {
parse,
dump,
};

export default selfServiceProfileHandler;
2 changes: 2 additions & 0 deletions src/tools/auth0/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as themes from './themes';
import * as forms from './forms';
import * as flows from './flows';
import * as flowVaultConnections from './flowVaultConnections';
import * as selfServiceProfiles from './selfServiceProfiles';

import { AssetTypes } from '../../../types';
import APIHandler from './default';
Expand Down Expand Up @@ -66,6 +67,7 @@ const auth0ApiHandlers: { [key in AssetTypes]: any } = {
forms,
flows,
flowVaultConnections,
selfServiceProfiles,
};

export default auth0ApiHandlers as {
Expand Down
Loading

0 comments on commit a13e794

Please sign in to comment.