Skip to content
Merged
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
19 changes: 19 additions & 0 deletions examples/markdown/docs/custom-objects/Event__c.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ Represents an event that people can register for.

*Location*

---
### Social Security Number

Used to store the U.S. social security number in 9 digit format.

**Compliance Category**
PII

**Security Classification**
Internal

**API Name**

`ns__Social_Security_Number__c`

**Type**

*Text*

---
### Start Date
**Required**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>Social_Security_Number__c</fullName>
<externalId>false</externalId>
<label>Social Security Number</label>
<description>Used to store the U.S. social security number in 9 digit format.</description>
<length>9</length>
<trackTrending>false</trackTrending>
<type>Text</type>
<complianceCategory>PII</complianceCategory>
<securityClassification>Internal</securityClassification>
</CustomField>
5 changes: 5 additions & 0 deletions src/cli/commands/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,9 @@ export const markdownOptions: Record<keyof CliConfigurableMarkdownConfig, Option
describe: 'The title of the reference guide.',
default: markdownDefaults.referenceGuideTitle,
},
includeFieldSecurityMetadata: {
type: 'boolean',
describe: 'Whether to include the compliance category and security classification for fields in the generated files.',
default: markdownDefaults.includeFieldSecurityMetadata,
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default class CustomFieldMetadataBuilder {
description: this.description,
parentName: 'MyObject',
required: false,
securityClassification: 'Internal',
complianceCategory: 'PII',
};
}
}
1 change: 1 addition & 0 deletions src/core/markdown/__test__/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function generateDocs(bundles: UnparsedSourceBundle[], config?: Partial<M
linkingStrategy: 'relative',
excludeTags: [],
referenceGuideTitle: 'Apex Reference Guide',
includeFieldSecurityMetadata: true,
exclude: [],
...config,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const defaultMarkdownGeneratorConfig: MarkdownGeneratorConfig = {
sortAlphabetically: false,
linkingStrategy: 'relative',
referenceGuideTitle: 'Apex Reference Guide',
includeFieldSecurityMetadata: true,
exclude: [],
excludeTags: [],
};
Expand Down
10 changes: 10 additions & 0 deletions src/core/markdown/adapters/type-to-renderable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ function fieldMetadataToRenderable(
apiName: getApiName(field.name, config),
fieldType: field.type,
required: field.required,
complianceCategory: renderComplianceCategory(field.complianceCategory, config),
securityClassification: renderComplianceCategory(field.securityClassification, config),
pickListValues: field.pickListValues
? {
headingLevel: headingLevel + 1,
Expand Down Expand Up @@ -391,3 +393,11 @@ function getApiName(currentName: string, config: MarkdownGeneratorConfig) {
}
return currentName;
}

function renderComplianceCategory(complianceCategory: string | null, config: MarkdownGeneratorConfig) {
if(config.includeFieldSecurityMetadata) {
return complianceCategory;
} else {
return null;
}
}
10 changes: 10 additions & 0 deletions src/core/markdown/templates/custom-object-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export const customObjectTemplate = `
{{{renderContent description}}}
{{/if}}

{{#if complianceCategory}}
**Compliance Category**
{{complianceCategory}}
{{/if}}

{{#if securityClassification}}
**Security Classification**
{{securityClassification}}
{{/if}}

**API Name**

\`{{{apiName}}}\`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const customFieldContent = `
<trackFeedHistory>false</trackFeedHistory>
<type>Url</type>
<description>A Photo URL field</description>
<securityClassification>Internal</securityClassification>
<complianceCategory>PII</complianceCategory>
</CustomField>`;

describe('when parsing custom field metadata', () => {
Expand Down Expand Up @@ -107,6 +109,34 @@ describe('when parsing custom field metadata', () => {
assertEither(result, (data) => expect(data[0].type.description).toBe('A Photo URL field'));
});

test('the resulting type contains the correct security classification', async () => {
const unparsed: UnparsedCustomFieldBundle = {
type: 'customfield',
name: 'PhotoUrl__c',
parentName: 'MyFirstObject__c',
filePath: 'src/field/PhotoUrl__c.field-meta.xml',
content: customFieldContent,
};

const result = await reflectCustomFieldSources([unparsed])();

assertEither(result, (data) => expect(data[0].type.securityClassification).toBe('Internal'));
});

test('the resulting type contains the correct compliance category', async () => {
const unparsed: UnparsedCustomFieldBundle = {
type: 'customfield',
name: 'PhotoUrl__c',
parentName: 'MyFirstObject__c',
filePath: 'src/field/PhotoUrl__c.field-meta.xml',
content: customFieldContent,
};

const result = await reflectCustomFieldSources([unparsed])();

assertEither(result, (data) => expect(data[0].type.complianceCategory).toBe('PII'));
});

test('can parse picklist values when there are multiple picklist values available', async () => {
const unparsed: UnparsedCustomFieldBundle = {
type: 'customfield',
Expand Down
4 changes: 4 additions & 0 deletions src/core/reflection/sobject/reflect-custom-field-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type CustomFieldMetadata = {
parentName: string;
pickListValues?: string[];
required: boolean;
securityClassification: string | null;
complianceCategory: string | null;
};

export function reflectCustomFieldSources(
Expand Down Expand Up @@ -66,6 +68,8 @@ function toCustomFieldMetadata(parserResult: { CustomField: unknown }): CustomFi
const defaultValues = {
description: null,
required: false,
securityClassification: null,
complianceCategory: null,
};

return {
Expand Down
4 changes: 4 additions & 0 deletions src/core/reflection/sobject/reflect-custom-object-sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ function convertInlineFieldsToCustomFieldMetadata(
const label = inlineField.label ? (inlineField.label as string) : name;
const type = inlineField.type ? (inlineField.type as string) : null;
const required = inlineField.required ? (inlineField.required as boolean) : false;
const securityClassification = inlineField.securityClassification ? (inlineField.securityClassification as string) : null;
const complianceCategory = inlineField.complianceCategory ? (inlineField.complianceCategory as string) : null;

return {
type_name: 'customfield',
Expand All @@ -118,6 +120,8 @@ function convertInlineFieldsToCustomFieldMetadata(
parentName,
type,
required,
securityClassification,
complianceCategory,
pickListValues: getPickListValues(inlineField),
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/renderables/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ export type RenderableCustomField = {
type: 'field';
fieldType?: string | null;
required: boolean;
complianceCategory: string | null;
securityClassification: string | null;
};

export type RenderableCustomMetadata = {
Expand Down
1 change: 1 addition & 0 deletions src/core/shared/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type CliConfigurableMarkdownConfig = {
includeMetadata: boolean;
linkingStrategy: LinkingStrategy;
referenceGuideTitle: string;
includeFieldSecurityMetadata: boolean;
};

export type UserDefinedMarkdownConfig = {
Expand Down
1 change: 1 addition & 0 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const markdownDefaults = {
linkingStrategy: 'relative' as const,
referenceGuideTitle: 'Reference Guide',
excludeTags: [],
includeFieldSecurityMetadata: false,
};

export const openApiDefaults = {
Expand Down