Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getNext = (prev: string): string =>
typeof edit === 'string'
? edit
: applyEdits(
prev,
// TODO(chris): remove `.slice()` (which guards against mutation) once
// https://github.com/Microsoft/node-jsonc-parser/pull/12 is merged in.
setProperty(prev, edit.path.slice(), edit.value, {
tabSize: 2,
insertSpaces: true,
eol: '\n',
})
)
if (isInPage) {
}
const totalAdditions = calculateDiff('added')
const totalDeletions = calculateDiff('deleted')
const status = campaign
? campaign.__typename === 'CampaignPlan'
? campaign.status
: campaign.changesetCreationStatus
: null
const currentSpec = campaign && campaign.__typename === 'CampaignPlan' ? parseJSONC(campaign.arguments) : undefined
// Tracks if a refresh of the campaignPlan is required before the campaign can be created
const previewRefreshNeeded =
!currentSpec ||
(campaignPlanArguments && !isEqual(currentSpec, parseJSONC(campaignPlanArguments))) ||
(status && status.state !== GQL.BackgroundProcessState.COMPLETED)
return (
<>
<form>
<div>
<h2>
</h2></div></form>
function getExternalURLPlaceholders(config: string): { externalURL: string; externalURLRegexp: string } {
let externalURL
let externalURLRegexp
try {
externalURL = jsonc.parse(config).externalURL
externalURLRegexp = externalURL.replace(/\//g, '\\/')
} catch {
/* not necessarily an error, config might be empty */
}
if (!externalURL) {
externalURL = ''
externalURLRegexp = ''
}
return { externalURL, externalURLRegexp }
}
export async function createAuthProvider(
gqlClient: GraphQLClient,
authProvider: GitHubAuthProvider | GitLabAuthProvider | OpenIDConnectAuthProvider | SAMLAuthProvider
): Promise {
const siteConfig = await fetchSiteConfiguration(gqlClient).toPromise()
const siteConfigParsed: SiteConfiguration = jsonc.parse(siteConfig.configuration.effectiveContents)
const authProviders = siteConfigParsed['auth.providers']
if (
authProviders &&
authProviders.filter(p => p.type === authProvider.type && (p as any).displayName === authProvider.displayName)
.length > 0
) {
return () => Promise.resolve() // provider already exists
}
const editFns = [
(contents: string) =>
jsoncEdit.setProperty(contents, ['auth.providers', -1], authProvider, {
eol: '\n',
insertSpaces: true,
tabSize: 2,
}),
]
run: config => {
const value = '?membership=true'
const edits = setProperty(config, ['projectQuery', -1], value, defaultFormattingOptions)
return { edits, selectText: value }
},
},
const addGitLab: ConfigInsertionFunction = config => {
const tokenPlaceholder =
''
const value: GitLabConnection = {
url: 'https://gitlab.example.com',
token: tokenPlaceholder,
}
const edits = setProperty(config, ['gitlab', -1], value, defaultFormattingOptions)
return { edits, selectText: tokenPlaceholder }
}
export function modifyJSONC(text: string, path: jsonc.JSONPath, f: (oldValue: jsonc.Node | undefined) => any): any {
const old = jsonc.findNodeAtLocation(jsonc.parseTree(text), path)
return jsonc.applyEdits(
text,
jsoncEdit.setProperty(text, path, f(old), {
eol: '\n',
insertSpaces: true,
tabSize: 2,
})
)
}
run: config => {
const value = ''
const edits = setProperty(config, ['token'], value, defaultFormattingOptions)
return { edits, selectText: value }
},
},
run: config => {
const value = 'path/to/repository'
const edits = setProperty(config, ['repos', -1], value, defaultFormattingOptions)
return { edits, selectText: value }
},
},
const addAWSCodeCommit: ConfigInsertionFunction = config => {
const value: AWSCodeCommitConnection = {
region: '' as any,
accessKeyID: '',
secretAccessKey: '',
}
const edits = setProperty(config, ['awsCodeCommit', -1], value, defaultFormattingOptions)
return { edits, selectText: '""', cursorOffset: 1 }
}