Skip to content

Commit

Permalink
fix: AppSync Functions fail to compile on Windows OS (#24)
Browse files Browse the repository at this point in the history
fix(cdk): fixed bug related to default UI config file settings
  • Loading branch information
flamingquaks authored May 8, 2024
1 parent 40dc1b2 commit 6a9779b
Show file tree
Hide file tree
Showing 35 changed files with 128 additions and 269 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ lib/user-interface/genai-newsletter-ui/src/API.ts
lib/user-interface/genai-newsletter-ui/src/graphql/*
lib/user-interface/genai-newsletter-ui/vite.config.ts
vite.config.ts
misc/
misc/
lib/api/functions/out/*
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ lib/user-interface/genai-newsletter-ui/.env.local
lib/user-interface/genai-newsletter-ui/public/amplifyconfiguration.json
lib/user-interface/genai-newsletter-ui/.DS_Store
.DS_Store

lib/api/functions/out
pages/.vitepress/cache
1 change: 1 addition & 0 deletions .gitlab/ci/.gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ build-branch:
artifacts:
paths:
- ./lib/user-interface/genai-newsletter-ui/dist
- ./lib/api/functions/out
cache:
policy: push
when: on_success
Expand Down
41 changes: 41 additions & 0 deletions lib/api/functions/bundle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: MIT-0
*
* This file is used to properly compile the AppSync Javascript Functions (Resolver and Pipeline)
* from TypeScript to Javascript.
*
* The build process is done by using esbuild. It is executed by node rather than esbuild to generate paths
* to files dynamically without using 'globs' since they are not safe for windows
*/

import esbuild from 'esbuild'
import fs from 'fs'
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')
})

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))
10 changes: 0 additions & 10 deletions lib/api/functions/package-lock.json

This file was deleted.

7 changes: 0 additions & 7 deletions lib/api/functions/package.json

This file was deleted.

3 changes: 1 addition & 2 deletions lib/api/functions/pipeline/createDataFeed/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import { type CreateDataFeedInput } from '../../../../shared/api'

export function request (ctx: Context): LambdaRequest {
const { args } = ctx
const identity = ctx.identity as AppSyncIdentityLambda
const input = args.input as CreateDataFeedInput
const input = args.input
if (input.isPrivate === undefined || input.isPrivate === null) {
input.isPrivate = true
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/pipeline/createNewsletter/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import { type CreateNewsletterInput } from '../../../../shared/api'

export function request (ctx: Context): LambdaRequest {
const { args } = ctx
const identity = ctx.identity as AppSyncIdentityLambda
const input = args.input as CreateNewsletterInput
const input = args.input
if (input.isPrivate === undefined || input.isPrivate === null) {
input.isPrivate = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
type DynamoDBQueryRequest
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { type ListDataFeedsInput } from 'lib/shared/api'
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 as ListDataFeedsInput
const input = ctx.args.input
const includeDiscoverable = input?.includeDiscoverable !== undefined ? input.includeDiscoverable : ctx.stash.lookupDefinition.includeDiscoverable ?? false
if (includeDiscoverable === false) {
runtime.earlyReturn(ctx.prev.result)
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/pipeline/listDataFeedsOwned/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import {
type AppSyncIdentityLambda
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { type ListDataFeedsInput } from 'lib/shared/api'
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 as ListDataFeedsInput
const input = ctx.args.input
const includeOwned = input?.includeOwned !== undefined ? input.includeOwned : ctx.stash.lookupDefinition.includeOwned ?? true
if (includeOwned === false) {
runtime.earlyReturn(ctx.prev.result)
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/pipeline/listDataFeedsShared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import {
type DynamoDBQueryRequest
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { type ListDataFeedsInput } from 'lib/shared/api'
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 as ListDataFeedsInput
const input = ctx.args.input
const includeShared = input?.includeShared !== undefined ? input.includeShared : ctx.stash.lookupDefinition.includeShared ?? false
if (includeShared === false) {
runtime.earlyReturn(ctx.prev.result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import {
type DynamoDBQueryRequest
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { type ListNewslettersInput } from 'lib/shared/api'
import { addAccountToItems, convertFieldIdsToObjectIds, filterForDuplicatesById } from '../../resolver-helper'

export function request (ctx: Context): DynamoDBQueryRequest {
const tableSKIndex = 'newsletter-item-type-index' // CDK doesn't have env variables yet
const { nextToken, limit = 500 } = ctx.args
const input = ctx.args.input as ListNewslettersInput
const input = ctx.args.input
const includeDiscoverable = input?.includeDiscoverable !== undefined ? input.includeDiscoverable : ctx.stash.lookupDefinition.includeDiscoverable ?? false
if (includeDiscoverable === true) {
return ddb.query({
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/pipeline/listNewslettersOwned/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import {
type AppSyncIdentityLambda
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { type ListNewslettersInput } from 'lib/shared/api'
import { addAccountToItems, convertFieldIdsToObjectIds, filterForDuplicatesById } from '../../resolver-helper'

export function request (ctx: Context): DynamoDBQueryRequest {
const identity = ctx.identity as AppSyncIdentityLambda
const tableSKIndex = 'newsletter-item-type-index' // CDK doesn't have env variables yet
const { nextToken, limit = 1000 } = ctx.args
const input = ctx.args.input as ListNewslettersInput
const input = ctx.args.input
const includeOwned = input?.includeOwned !== undefined ? input.includeOwned : ctx.stash.lookupDefinition.includeOwned ?? false as boolean
if (includeOwned === true) {
return ddb.query({
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/pipeline/listNewslettersShared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import {
type AppSyncIdentityLambda
} from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { type ListNewslettersInput } from 'lib/shared/api'
import { addAccountToItems, convertFieldIdsToObjectIds, filterForDuplicatesById } from '../../resolver-helper'

export function request (ctx: Context): DynamoDBQueryRequest {
// const { tableSKIndex } = ctx.env
const identity = ctx.identity as AppSyncIdentityLambda
const tableSKIndex = 'newsletter-item-type-index' // CDK doesn't have env variables yet
const { nextToken, limit = 500 } = ctx.args
const input = ctx.args.input as ListNewslettersInput
const input = ctx.args.input
const includeShared = input?.includeShared !== undefined ? input.includeShared : ctx.stash.lookupDefinition.includeShared ?? false
if (includeShared === true) {
return ddb.query({
Expand Down
2 changes: 1 addition & 1 deletion lib/api/functions/pipeline/listPublications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const response = (ctx: Context): any => {
if (ctx.error !== undefined && ctx.error !== null) {
util.error(ctx.error.message, ctx.error.type)
}
const items = []
const items: any[] = []
if (ctx.result.items !== undefined) {
for (const item of ctx.result.items) {
const { emailKey, createdAt, newsletterId, sk, accountId } = item
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/pipeline/subscribeToNewsletter/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import { type SubscribeToNewsletterInput } from 'lib/shared/api'

export function request (ctx: Context): LambdaRequest {
const { args } = ctx
const identity = ctx.identity as AppSyncIdentityLambda
const input = args.input as SubscribeToNewsletterInput
const input = args.input
if (input.id === undefined || input.id === null) {
util.error('Newsletter ID is required', 'ValidationException')
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import { type UnsubscribeFromNewsletterInput } from 'lib/shared/api'

export function request (ctx: Context): LambdaRequest {
const { args } = ctx
const identity = ctx.identity as AppSyncIdentityLambda
const input = args.input as UnsubscribeFromNewsletterInput
const input = args.input
if (input.id === undefined || input.id === null) {
util.error('Newsletter ID is required', 'ValidationException')
}
Expand Down
8 changes: 2 additions & 6 deletions lib/api/functions/pipeline/updateNewsletter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import {
util,
type DynamoDBUpdateItemRequest
} from '@aws-appsync/utils'
import { type UpdateNewsletterInput } from '../../../../shared/api'

export function request (ctx: Context): DynamoDBUpdateItemRequest {
const input: UpdateNewsletterInput = ctx.args.input
const input = ctx.args.input
let expression = 'SET '
const expressionNames: Record<string, string> = {}
const expressionValues: Record<
string,
string | number | object | string[] | boolean
> = {}
const expressionValues: Record<string, any> = {}
let updates = 0
if (input.title != null) {
expression += '#title = :title, '
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util } from '@aws-appsync/utils'
import { type SubscribeToNewsletterInput } from 'lib/shared/api'

export function request (ctx: Context): void {
const { args } = ctx
ctx.stash.root = 'Newsletter'
const input = args.input as SubscribeToNewsletterInput
const input = args.input
if (input.id === undefined || input.id === null) {
util.error('Newsletter ID is required', 'ValidationException')
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/createNewsletter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
*/

import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import { type CreateNewsletterInput } from 'lib/shared/api'

export function request (ctx: Context): LambdaRequest {
ctx.stash.root = 'Newsletter'
const { args } = ctx
const identity = ctx.identity as AppSyncIdentityLambda
const input = args.input as CreateNewsletterInput
const input = args.input
return {
operation: 'Invoke',
payload: {
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/flagArticle/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { type Context, util } from '@aws-appsync/utils'
import * as ddb from '@aws-appsync/utils/dynamodb'
import { type FlagArticleInput } from 'lib/shared/api'

export function request (ctx: Context): any {
ctx.stash.root = 'Article'
const { args } = ctx
const input = args.input as FlagArticleInput
const input = args.input
if (input.dataFeedId === undefined || input.dataFeedId === null) {
util.error('DataFeedID is required', 'ValidationException')
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/getDataFeed/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util } from '@aws-appsync/utils'
import { type GetDataFeedInput } from 'lib/shared/api'

export function request (ctx: Context): any {
const { args } = ctx
ctx.stash.root = 'DataFeed'
const input = args.input as GetDataFeedInput
const input = args.input
if (input.id === undefined || input.id === null) {
util.error('DataFeedID is required', 'ValidationException')
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/getPublication/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util } from '@aws-appsync/utils'
import { type GetPublicationInput } from 'lib/shared/api'

export function request (ctx: Context): any {
const { args } = ctx
ctx.stash.root = 'Publication'
const input = args.input as GetPublicationInput
const input = args.input
if (input.newsletterId === undefined || input.newsletterId === null) {
util.error('NewsletterId is required', 'ValidationException')
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/listDataFeeds/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { type Context, util } from '@aws-appsync/utils'
import { type ListDataFeedsInput } from 'lib/shared/api'

export function request (ctx: Context): any {
const input = ctx.args.input as ListDataFeedsInput
const input = ctx.args.input
ctx.stash.root = 'DataFeeds'
if (input === undefined || (input.includeOwned === undefined && input.includeShared === undefined && input.includeDiscoverable === undefined)) {
ctx.stash.lookupDefinition = {
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/listNewsletters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
*/

import { type Context, util } from '@aws-appsync/utils'
import { type ListNewslettersInput } from 'lib/shared/api'

export function request (ctx: Context): any {
ctx.stash.root = 'Newsletters'
console.log('[listNewslettersResolverRequest]', { ctx })
const input = ctx.args.input as ListNewslettersInput
const input = ctx.args.input
if (input === undefined || (input.includeDiscoverable === undefined && input.includeOwned === undefined && input.includeShared === undefined)) {
ctx.stash.lookupDefinition = {
includeOwned: true,
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/listPublications/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { type Context, util } from '@aws-appsync/utils'
import { type ListPublicationsInput } from 'lib/shared/api'

export function request (ctx: Context): any {
ctx.stash.root = 'Publications'
const input = ctx.args.input as ListPublicationsInput
const input = ctx.args.input
if (input.id === undefined || input.id === null) {
util.error('NewsletterId is required', 'ValidationException')
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/subscribeToNewsletter/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util } from '@aws-appsync/utils'
import { type SubscribeToNewsletterInput } from 'lib/shared/api'

export function request (ctx: Context): void {
const { args } = ctx
ctx.stash.root = 'Newsletter'
const input = args.input as SubscribeToNewsletterInput
const input = args.input
if (input.id === undefined || input.id === null) {
util.error('Newsletter ID is required', 'ValidationException')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
*/

import { type Context, util, type LambdaRequest, type AppSyncIdentityLambda } from '@aws-appsync/utils'
import { type UnsubscribeFromNewsletterInput } from 'lib/shared/api'

export function request (ctx: Context): LambdaRequest {
ctx.stash.root = 'Newsletter'
const { args } = ctx
const identity = ctx.identity as AppSyncIdentityLambda
const input = args.input as UnsubscribeFromNewsletterInput
const input = args.input
if (input.id === undefined || input.id === null) {
util.error('Newsletter ID is required', 'ValidationException')
}
Expand Down
3 changes: 1 addition & 2 deletions lib/api/functions/resolver/updateDataFeed/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { type Context, util } from '@aws-appsync/utils'
import { type UpdateDataFeedInput } from 'lib/shared/api'

export function request (ctx: Context): any {
ctx.stash.root = 'DataFeed'
const { args } = ctx
const input = args.input as UpdateDataFeedInput
const input = args.input
if (input.id === undefined || input.id === null) {
util.error('DataFeedID is required', 'ValidationException')
}
Expand Down
Loading

0 comments on commit 6a9779b

Please sign in to comment.