Skip to content

Commit

Permalink
style(formatting): cleaned code formatting using prettier
Browse files Browse the repository at this point in the history
Commit changes code style only, no logic or functionality changed

re: #55
  • Loading branch information
flamingquaks committed May 28, 2024
1 parent 4a43a8d commit 6f284ea
Show file tree
Hide file tree
Showing 102 changed files with 2,292 additions and 1,335 deletions.
70 changes: 54 additions & 16 deletions cli/config-manage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ if (fs.existsSync(deployConfig)) {
const configFromFile: DeployConfig = JSON.parse(
fs.readFileSync(deployConfig, 'utf8')
)
console.log(formatText('A configuration already exists.', { bold: true, backgroundColor: 'bg-yellow' }))
console.log(
formatText('A configuration already exists.', {
bold: true,
backgroundColor: 'bg-yellow'
})
)
let existingConfigChoice: string | null = null
let readyToProceed = false
while (!readyToProceed) {
Expand Down Expand Up @@ -289,16 +294,30 @@ if (['UPDATE', 'NEW'].includes(configStyle)) {
* Does the user want to configure a Host Name & ACM Cert for the Frontend Cloudfront
*/
let configHostname = false
if (config.ui?.acmCertificateArn === undefined || config.ui.hostName === undefined) {
console.log(formatText('Do you want to configure a custom hostname for the frontend?',
{ textColor: 'blue' }))
console.log(formatText('Requires a hostname & a pre-existing AWS Certificate Manager public cert ARN.' +
'For more information, visit https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html',
{ italic: true }))
if (
config.ui?.acmCertificateArn === undefined ||
config.ui.hostName === undefined
) {
console.log(
formatText(
'Do you want to configure a custom hostname for the frontend?',
{ textColor: 'blue' }
)
)
console.log(
formatText(
'Requires a hostname & a pre-existing AWS Certificate Manager public cert ARN.' +
'For more information, visit https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html',
{ italic: true }
)
)
let loopA = true
while (loopA) {
const response = prompter(
formatText('Do you want to proceed? (y/N):', { bold: true, textColor: 'blue' }),
formatText('Do you want to proceed? (y/N):', {
bold: true,
textColor: 'blue'
}),
'N'
)
if (response.toLowerCase() === 'y') {
Expand All @@ -321,19 +340,28 @@ if (['UPDATE', 'NEW'].includes(configStyle)) {
if (configHostname) {
let loopB = true
while (loopB) {
const existingHostname = ((config.ui?.hostName) != null) ? config.ui.hostName : ''
const existingHostname =
config.ui?.hostName != null ? config.ui.hostName : ''
const response = prompter(
formatText(`Enter the hostname you want to use for the frontend:(${existingHostname})`, { textColor: 'blue' })
formatText(
`Enter the hostname you want to use for the frontend:(${existingHostname})`,
{ textColor: 'blue' }
)
)
const hostnameRegex = /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/
const hostnameRegex =
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings containing many repetitions of '0-0a'.

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with '0' and containing many repetitions of '0-0'.
if (response.length > 0 && hostnameRegex.test(response)) {
if (config.ui === undefined) {
config.ui = {}
}
config.ui.hostName = response
loopB = false
break
} else if (response.length < 1 && config.ui?.hostName !== undefined && config.ui.hostName !== null) {
} else if (
response.length < 1 &&
config.ui?.hostName !== undefined &&
config.ui.hostName !== null
) {
loopB = false
break
} else {
Expand All @@ -348,9 +376,15 @@ if (['UPDATE', 'NEW'].includes(configStyle)) {
}
let loopC = true
while (loopC) {
const existingAcmCert = ((config.ui?.acmCertificateArn) != null) ? config.ui.acmCertificateArn : ''
const existingAcmCert =
config.ui?.acmCertificateArn != null
? config.ui.acmCertificateArn
: ''
const response = prompter(
formatText(`Enter the ACM Certificate ARN you want to use for the frontend:(${existingAcmCert})`, { textColor: 'blue' })
formatText(
`Enter the ACM Certificate ARN you want to use for the frontend:(${existingAcmCert})`,
{ textColor: 'blue' }
)
)
const acmCertRegex = /^arn:aws:acm:\S+:\d+:\w+\/\S+$/
if (response.length > 0 && acmCertRegex.test(response)) {
Expand All @@ -360,8 +394,12 @@ if (['UPDATE', 'NEW'].includes(configStyle)) {
config.ui.acmCertificateArn = response
loopC = false
break
} else if (response.length < 1 && config.ui?.acmCertificateArn !== undefined && config.ui.acmCertificateArn !== null) {
loopC = false;
} else if (
response.length < 1 &&
config.ui?.acmCertificateArn !== undefined &&
config.ui.acmCertificateArn !== null
) {
loopC = false
break
} else {
console.log(
Expand Down
8 changes: 5 additions & 3 deletions cli/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import figlet from 'figlet'

const program = new Command()

console.log(figlet.textSync('GenAI Newsletter', {
font: 'Slant'
}))
console.log(
figlet.textSync('GenAI Newsletter', {
font: 'Slant'
})
)

program
.name('npm run config')
Expand Down
47 changes: 25 additions & 22 deletions lib/api/functions/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@ import path from 'path'

const outDir = path.join(__dirname, 'out')

const resolverFunctions = fs.readdirSync(path.join(__dirname, 'resolver')).map((functionName) => {
return path.join(__dirname, 'resolver', functionName, 'index.ts')
})
const pipelineFunctions = fs.readdirSync(path.join(__dirname, 'pipeline')).map((functionName) => {
return path.join(__dirname, 'pipeline', functionName, 'index.ts')
})
const resolverFunctions = fs
.readdirSync(path.join(__dirname, 'resolver'))
.map((functionName) => {
return path.join(__dirname, 'resolver', functionName, 'index.ts')
})
const pipelineFunctions = fs
.readdirSync(path.join(__dirname, 'pipeline'))
.map((functionName) => {
return path.join(__dirname, 'pipeline', functionName, 'index.ts')
})

esbuild.build({
bundle: true,
entryPoints: [
...resolverFunctions,
...pipelineFunctions
],
outdir: outDir,
sourcemap: 'inline',
sourcesContent: false,
external: ['@aws-appsync/utils'],
platform: 'node',
target: 'esnext',
format: 'esm',
minify: false,
logLevel: 'info'
}).catch(() => process.exit(1))
esbuild
.build({
bundle: true,
entryPoints: [...resolverFunctions, ...pipelineFunctions],
outdir: outDir,
sourcemap: 'inline',
sourcesContent: false,
external: ['@aws-appsync/utils'],
platform: 'node',
target: 'esnext',
format: 'esm',
minify: false,
logLevel: 'info'
})
.catch(() => process.exit(1))
7 changes: 6 additions & 1 deletion lib/api/functions/pipeline/createDataFeed/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import {
type Context,
util,
type LambdaRequest,
type AppSyncIdentityLambda
} from '@aws-appsync/utils'

export function request (ctx: Context): LambdaRequest {
const { args } = ctx
Expand Down
7 changes: 6 additions & 1 deletion lib/api/functions/pipeline/createNewsletter/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import {
type Context,
util,
type LambdaRequest,
type AppSyncIdentityLambda
} from '@aws-appsync/utils'

export function request (ctx: Context): LambdaRequest {
const { args } = ctx
Expand Down
19 changes: 15 additions & 4 deletions lib/api/functions/pipeline/filterListByAuthorization/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,28 @@
* SPDX-License-Identifier: MIT-0
*/

import { type LambdaRequest, util, type Context, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import {
type LambdaRequest,
util,
type Context,
type AppSyncIdentityLambda
} from '@aws-appsync/utils'
import { convertAvpObjectsToGraphql } from '../../resolver-helper'

export function request (ctx: Context): LambdaRequest {
console.log(`[Filter List by Authorization Request] request ctx ${JSON.stringify(ctx)}`)
console.log(
`[Filter List by Authorization Request] request ctx ${JSON.stringify(ctx)}`
)
const { source, args } = ctx
const identity = ctx.identity as AppSyncIdentityLambda
return {
operation: 'Invoke',
payload: {
userId: identity.resolverContext.userId,
accountId: identity.resolverContext.accountId,
requestContext: JSON.parse(identity.resolverContext.requestContext as string),
requestContext: JSON.parse(
identity.resolverContext.requestContext as string
),
result: ctx.prev.result,
arguments: args,
source
Expand All @@ -33,7 +42,9 @@ export function response (ctx: Context): any {
if (result.isAuthorized !== true) {
util.unauthorized()
}
console.log('[IsAuthorized] response result $', { result: JSON.stringify(result) })
console.log('[IsAuthorized] response result $', {
result: JSON.stringify(result)
})
return {
isAuthorized: true,
items: convertAvpObjectsToGraphql(result)
Expand Down
5 changes: 4 additions & 1 deletion lib/api/functions/pipeline/getDataFeed/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { type DynamoDBGetItemRequest, type Context } from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { addAccountToItem, convertFieldIdToObjectId } from '../../resolver-helper'
import {
addAccountToItem,
convertFieldIdToObjectId
} from '../../resolver-helper'

export function request (ctx: Context): DynamoDBGetItemRequest {
const { id } = ctx.args.input
Expand Down
9 changes: 5 additions & 4 deletions lib/api/functions/pipeline/getNewsletter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import {
type DynamoDBGetItemRequest
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { addAccountToItem, convertFieldIdToObjectId } from '../../resolver-helper'
import {
addAccountToItem,
convertFieldIdToObjectId
} from '../../resolver-helper'

export function request (
ctx: Context
): DynamoDBGetItemRequest {
export function request (ctx: Context): DynamoDBGetItemRequest {
console.log('getNewsletter request', { ctx })
const { id } = ctx.args.input
return ddb.get({
Expand Down
8 changes: 6 additions & 2 deletions lib/api/functions/pipeline/getPublication/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
type DynamoDBGetItemRequest
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { addAccountToItem, convertFieldIdToObjectId } from '../../resolver-helper'
import {
addAccountToItem,
convertFieldIdToObjectId
} from '../../resolver-helper'

export function request (ctx: Context): DynamoDBGetItemRequest {
const { newsletterId, publicationId } = ctx.args.input
Expand All @@ -20,7 +23,8 @@ export const response = (ctx: Context): any => {
if (ctx.error !== undefined && ctx.error !== null) {
util.error(ctx.error.message, ctx.error.type)
}
const { emailKey, createdAt, newsletterId, publicationId, accountId } = ctx.result
const { emailKey, createdAt, newsletterId, publicationId, accountId } =
ctx.result
let path = ''
if (emailKey !== undefined) {
path = emailKey
Expand Down
11 changes: 9 additions & 2 deletions lib/api/functions/pipeline/isAuthorized/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
* SPDX-License-Identifier: MIT-0
*/

import { type LambdaRequest, util, type Context, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import {
type LambdaRequest,
util,
type Context,
type AppSyncIdentityLambda
} from '@aws-appsync/utils'
import { convertAvpObjectToGraphql } from '../../resolver-helper'

export function request (ctx: Context): LambdaRequest {
Expand All @@ -15,7 +20,9 @@ export function request (ctx: Context): LambdaRequest {
payload: {
userId: identity.resolverContext.userId,
accountId: identity.resolverContext.accountId,
requestContext: JSON.parse(identity.resolverContext.requestContext as string),
requestContext: JSON.parse(
identity.resolverContext.requestContext as string
),
result: ctx.prev.result,
arguments: args,
source,
Expand Down
4 changes: 3 additions & 1 deletion lib/api/functions/pipeline/listDataFeedsById/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export function request (ctx: Context): DynamoDBBatchGetItemRequest {
return {
operation: 'BatchGetItem',
tables: {
[NEWSLETTER_TABLE]: ctx.args.dataFeedIds.map((dataFeedId: string) => util.dynamodb.toMapValues({ dataFeedId }))
[NEWSLETTER_TABLE]: ctx.args.dataFeedIds.map((dataFeedId: string) =>
util.dynamodb.toMapValues({ dataFeedId })
)
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions lib/api/functions/pipeline/listDataFeedsDiscoverable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ import {
type DynamoDBQueryRequest
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { addAccountToItems, convertFieldIdsToObjectIds, filterForDuplicatesById } from '../../resolver-helper'
import {
addAccountToItems,
convertFieldIdsToObjectIds,
filterForDuplicatesById
} from '../../resolver-helper'

export function request (ctx: Context): DynamoDBQueryRequest {
const dataFeedTypeIndex = 'type-index' // TODO - Make ENV variable
const input = ctx.args.input
const includeDiscoverable = input?.includeDiscoverable !== undefined ? input.includeDiscoverable : ctx.stash.lookupDefinition.includeDiscoverable ?? false
const includeDiscoverable =
input?.includeDiscoverable !== undefined
? input.includeDiscoverable
: ctx.stash.lookupDefinition.includeDiscoverable ?? false
if (includeDiscoverable === false) {
runtime.earlyReturn(ctx.prev.result)
}
Expand Down
11 changes: 9 additions & 2 deletions lib/api/functions/pipeline/listDataFeedsOwned/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ import {
type AppSyncIdentityLambda
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { addAccountToItems, convertFieldIdsToObjectIds, filterForDuplicatesById } from '../../resolver-helper'
import {
addAccountToItems,
convertFieldIdsToObjectIds,
filterForDuplicatesById
} from '../../resolver-helper'
const dataFeedTypeIndex = 'type-index' // TODO - Make ENV variable

export function request (ctx: Context): DynamoDBQueryRequest {
const identity = ctx.identity as AppSyncIdentityLambda
const input = ctx.args.input
const includeOwned = input?.includeOwned !== undefined ? input.includeOwned : ctx.stash.lookupDefinition.includeOwned ?? true
const includeOwned =
input?.includeOwned !== undefined
? input.includeOwned
: ctx.stash.lookupDefinition.includeOwned ?? true
if (includeOwned === false) {
runtime.earlyReturn(ctx.prev.result)
}
Expand Down
Loading

0 comments on commit 6f284ea

Please sign in to comment.