Skip to content

Commit

Permalink
Merge branch 'main' into fix/push-notification-flush-events
Browse files Browse the repository at this point in the history
  • Loading branch information
tyllark authored Jul 31, 2024
2 parents 1ff5395 + c0f6f09 commit 2cd2434
Show file tree
Hide file tree
Showing 124 changed files with 6,345 additions and 3,577 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ jobs:
with:
version: 9

- name: Setup aft
shell: bash # Run in bash regardless of platform
run: dart pub global activate -spath packages/aft

- name: aft link
run: aft link

- name: Get Packages
working-directory: actions
run: dart pub get
Expand All @@ -59,6 +66,13 @@ jobs:
with:
sdk: 3.3.0

- name: Setup aft
shell: bash # Run in bash regardless of platform
run: dart pub global activate -spath packages/aft

- name: aft link
run: aft link

- name: Get Packages
working-directory: actions
run: dart pub get
Expand Down
4 changes: 2 additions & 2 deletions actions/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies:
aws_common: ^0.6.1
collection: ^1.18.0
js: ^0.6.7
json_annotation: ">=4.8.1 <4.9.0"
json_annotation: ">=4.9.0 <4.10.0"
path: ">=1.8.0 <2.0.0"
process: ^5.0.0
retry: ^3.1.2
Expand All @@ -24,7 +24,7 @@ dev_dependencies:
build_runner: ^2.4.0
build_test: ^2.2.0
checks: ^0.2.2
json_serializable: 6.7.1
json_serializable: 6.8.0
test: ^1.22.1

aft:
Expand Down
5 changes: 5 additions & 0 deletions infra-gen2/backends/auth/email-sign-in/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# amplify
node_modules
.amplify
amplify_outputs*
amplifyconfiguration*
14 changes: 14 additions & 0 deletions infra-gen2/backends/auth/email-sign-in/amplify/auth/resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineAuth } from "@aws-amplify/backend";

/**
* Define and configure your auth resource
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
*/
export const auth = defineAuth({
loginWith: {
email: true,
},
});
25 changes: 25 additions & 0 deletions infra-gen2/backends/auth/email-sign-in/amplify/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineBackend } from "@aws-amplify/backend";
import { addAuthUserExtensions } from "infra-common";
import { auth } from "./auth/resource";

const backend = defineBackend({
auth,
});

const resources = backend.auth.resources;
const { userPool, cfnResources } = resources;
const { stack } = userPool;
const { cfnUserPool } = cfnResources;

// Adds infra for creating/deleting users via App Sync and fetching confirmation
// and MFA codes from App Sync.
const customOutputs = addAuthUserExtensions({
name: "email-sign-in",
stack,
userPool,
cfnUserPool,
});
backend.addOutput(customOutputs);
3 changes: 3 additions & 0 deletions infra-gen2/backends/auth/email-sign-in/amplify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
17 changes: 17 additions & 0 deletions infra-gen2/backends/auth/email-sign-in/amplify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"$amplify/*": [
"../.amplify/generated/*"
]
}
}
}
5 changes: 5 additions & 0 deletions infra-gen2/backends/auth/email-sign-in/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "email-sign-in",
"version": "1.0.0",
"main": "index.js"
}
5 changes: 5 additions & 0 deletions infra-gen2/backends/auth/phone-sign-in/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# amplify
node_modules
.amplify
amplify_outputs*
amplifyconfiguration*
14 changes: 14 additions & 0 deletions infra-gen2/backends/auth/phone-sign-in/amplify/auth/resource.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineAuth } from "@aws-amplify/backend";

/**
* Define and configure your auth resource
* @see https://docs.amplify.aws/gen2/build-a-backend/auth
*/
export const auth = defineAuth({
loginWith: {
phone: true,
},
});
25 changes: 25 additions & 0 deletions infra-gen2/backends/auth/phone-sign-in/amplify/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { defineBackend } from "@aws-amplify/backend";
import { addAuthUserExtensions } from "infra-common";
import { auth } from "./auth/resource";

const backend = defineBackend({
auth,
});

const resources = backend.auth.resources;
const { userPool, cfnResources } = resources;
const { stack } = userPool;
const { cfnUserPool } = cfnResources;

// Adds infra for creating/deleting users via App Sync and fetching confirmation
// and MFA codes from App Sync.
const customOutputs = addAuthUserExtensions({
name: "phone-sign-in",
stack,
userPool,
cfnUserPool,
});
backend.addOutput(customOutputs);
3 changes: 3 additions & 0 deletions infra-gen2/backends/auth/phone-sign-in/amplify/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
17 changes: 17 additions & 0 deletions infra-gen2/backends/auth/phone-sign-in/amplify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"$amplify/*": [
"../.amplify/generated/*"
]
}
}
}
5 changes: 5 additions & 0 deletions infra-gen2/backends/auth/phone-sign-in/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "phone-sign-in",
"version": "1.0.0",
"main": "index.js"
}
3 changes: 2 additions & 1 deletion infra-gen2/infra-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
".": "./dist/index.js"
},
"scripts": {
"build": "tsc"
"build": "tsc && npm run copy-graphql",
"copy-graphql": "cp -r ./src/schemas ./dist"
}
}
6 changes: 6 additions & 0 deletions infra-gen2/infra-common/src/auth-user-extensions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# auth-user-extensions

This directory contains extensions useful for managing authorized users, including:

- creating & deleting users via App Sync
- sending confirmation codes to App Sync instead of email/SMS
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { BackendBase } from "@aws-amplify/backend";
import { Stack } from "aws-cdk-lib";
import { CfnUserPool, IUserPool } from "aws-cdk-lib/aws-cognito";
import { addCreateUserLambda } from "./create-user-lambda";
import { addCustomSenderLambda } from "./custom-sender-lambda";
import { addDeleteUserLambda } from "./delete-user-lambda";
import { addUserGraphql } from "./user-graphql";

type AmplifyOutputs = Parameters<BackendBase["addOutput"]>[0];

export const addAuthUserExtensions = ({
name,
stack,
userPool,
cfnUserPool,
}: {
name: string;
stack: Stack;
userPool: IUserPool;
cfnUserPool: CfnUserPool;
}): AmplifyOutputs => {
const graphQL = addUserGraphql(stack);
addCustomSenderLambda({ name, stack, cfnUserPool, graphQL });
addCreateUserLambda({ name, stack, userPool, graphQL });
addDeleteUserLambda({ name, stack, userPool, graphQL });
return {
data: {
aws_region: stack.region,
url: graphQL.graphqlUrl,
api_key: graphQL.apiKey,
default_authorization_type: "API_KEY",
authorization_types: [],
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Stack } from "aws-cdk-lib";
import { GraphqlApi, MappingTemplate } from "aws-cdk-lib/aws-appsync";
import { IUserPool } from "aws-cdk-lib/aws-cognito";
import { Runtime } from "aws-cdk-lib/aws-lambda";
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
import path from "path";

export function addCreateUserLambda({
name,
stack,
graphQL,
userPool,
}: {
name: string;
stack: Stack;
graphQL: GraphqlApi;
userPool: IUserPool;
}) {
const createUserLambda = new NodejsFunction(stack, `${name}-createUser`, {
entry: path.resolve(__dirname, "..", "lambda-triggers", "create-user.js"),
runtime: Runtime.NODEJS_18_X,
environment: {
USER_POOL_ID: userPool.userPoolId,
},
});
userPool.grant(
createUserLambda,
"cognito-idp:AdminCreateUser",
"cognito-idp:AdminSetUserPassword",
"cognito-idp:AdminSetUserMFAPreference",
"cognito-idp:AdminUpdateUserAttributes"
);
const createUserSource = graphQL.addLambdaDataSource(
`${name}-GraphQLApiCreateUserLambda`,
createUserLambda
);
createUserSource.createResolver(`${name}-MutationCreateUserResolver`, {
typeName: "Mutation",
fieldName: "createUser",
requestMappingTemplate: MappingTemplate.lambdaRequest(),
responseMappingTemplate: MappingTemplate.lambdaResult(),
});
}
Loading

0 comments on commit 2cd2434

Please sign in to comment.