diff --git a/samples/react/geo/geofence-control-map/.gitignore b/samples/react/geo/geofence-control-map/.gitignore new file mode 100644 index 0000000..46d86b8 --- /dev/null +++ b/samples/react/geo/geofence-control-map/.gitignore @@ -0,0 +1,44 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +#amplify-do-not-edit-begin +amplify/\#current-cloud-backend +amplify/.config/local-* +amplify/logs +amplify/mock-data +amplify/backend/amplify-meta.json +amplify/backend/.temp +build/ +dist/ +node_modules/ +aws-exports.js +awsconfiguration.json +amplifyconfiguration.json +amplifyconfiguration.dart +amplify-build-config.json +amplify-gradle-config.json +amplifytools.xcconfig +.secret-* +**.sample +#amplify-do-not-edit-end diff --git a/samples/react/geo/geofence-control-map/README.md b/samples/react/geo/geofence-control-map/README.md new file mode 100644 index 0000000..02aac3f --- /dev/null +++ b/samples/react/geo/geofence-control-map/README.md @@ -0,0 +1,70 @@ +# Getting Started with Create React App + +This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). + +## Available Scripts + +In the project directory, you can run: + +### `yarn start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in the browser. + +The page will reload if you make edits.\ +You will also see any lint errors in the console. + +### `yarn test` + +Launches the test runner in the interactive watch mode.\ +See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. + +### `yarn build` + +Builds the app for production to the `build` folder.\ +It correctly bundles React in production mode and optimizes the build for the best performance. + +The build is minified and the filenames include the hashes.\ +Your app is ready to be deployed! + +See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. + +### `yarn eject` + +**Note: this is a one-way operation. Once you `eject`, you can’t go back!** + +If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. + +Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. + +You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. + +## Learn More + +You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). + +To learn React, check out the [React documentation](https://reactjs.org/). + +### Code Splitting + +This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) + +### Analyzing the Bundle Size + +This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) + +### Making a Progressive Web App + +This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) + +### Advanced Configuration + +This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) + +### Deployment + +This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) + +### `yarn build` fails to minify + +This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) diff --git a/samples/react/geo/geofence-control-map/amplify/.config/project-config.json b/samples/react/geo/geofence-control-map/amplify/.config/project-config.json new file mode 100644 index 0000000..3ce4ee5 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/.config/project-config.json @@ -0,0 +1,17 @@ +{ + "projectName": "geofencecontrolmap", + "version": "3.1", + "frontend": "javascript", + "javascript": { + "framework": "react", + "config": { + "SourceDir": "src", + "DistributionDir": "build", + "BuildCommand": "npm run-script build", + "StartCommand": "npm run-script start" + } + }, + "providers": [ + "awscloudformation" + ] +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/README.md b/samples/react/geo/geofence-control-map/amplify/README.md new file mode 100644 index 0000000..7c0a9e2 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/README.md @@ -0,0 +1,8 @@ +# Getting Started with Amplify CLI +This directory was generated by [Amplify CLI](https://docs.amplify.aws/cli). + +Helpful resources: +- Amplify documentation: https://docs.amplify.aws +- Amplify CLI documentation: https://docs.amplify.aws/cli +- More details on this folder & generated files: https://docs.amplify.aws/cli/reference/files +- Join Amplify's community: https://amplify.aws/community/ diff --git a/samples/react/geo/geofence-control-map/amplify/backend/auth/geofencecontrolmap77dc1a87/cli-inputs.json b/samples/react/geo/geofence-control-map/amplify/backend/auth/geofencecontrolmap77dc1a87/cli-inputs.json new file mode 100644 index 0000000..e825cd6 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/auth/geofencecontrolmap77dc1a87/cli-inputs.json @@ -0,0 +1,61 @@ +{ + "version": "1", + "cognitoConfig": { + "identityPoolName": "geofencecontrolmap77dc1a87_identitypool_77dc1a87", + "allowUnauthenticatedIdentities": true, + "resourceNameTruncated": "geofen77dc1a87", + "userPoolName": "geofencecontrolmap77dc1a87_userpool_77dc1a87", + "autoVerifiedAttributes": [ + "email" + ], + "mfaConfiguration": "OFF", + "mfaTypes": [ + "SMS Text Message" + ], + "smsAuthenticationMessage": "Your authentication code is {####}", + "smsVerificationMessage": "Your verification code is {####}", + "emailVerificationSubject": "Your verification code", + "emailVerificationMessage": "Your verification code is {####}", + "defaultPasswordPolicy": false, + "passwordPolicyMinLength": 8, + "passwordPolicyCharacters": [], + "requiredAttributes": [ + "email" + ], + "aliasAttributes": [], + "userpoolClientGenerateSecret": false, + "userpoolClientRefreshTokenValidity": 30, + "userpoolClientWriteAttributes": [ + "email" + ], + "userpoolClientReadAttributes": [ + "email" + ], + "userpoolClientLambdaRole": "geofen77dc1a87_userpoolclient_lambda_role", + "userpoolClientSetAttributes": false, + "sharedId": "77dc1a87", + "resourceName": "geofencecontrolmap77dc1a87", + "authSelections": "identityPoolAndUserPool", + "useDefault": "default", + "userPoolGroupList": [ + "geofenceAdmin" + ], + "serviceName": "Cognito", + "usernameCaseSensitive": false, + "useEnabledMfas": true, + "authRoleArn": { + "Fn::GetAtt": [ + "AuthRole", + "Arn" + ] + }, + "unauthRoleArn": { + "Fn::GetAtt": [ + "UnauthRole", + "Arn" + ] + }, + "breakCircularDependency": true, + "dependsOn": [] + } +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/auth/userPoolGroups/user-pool-group-precedence.json b/samples/react/geo/geofence-control-map/amplify/backend/auth/userPoolGroups/user-pool-group-precedence.json new file mode 100644 index 0000000..6b236a9 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/auth/userPoolGroups/user-pool-group-precedence.json @@ -0,0 +1,6 @@ +[ + { + "groupName": "geofenceAdmin", + "precedence": 1 + } +] \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/backend-config.json b/samples/react/geo/geofence-control-map/amplify/backend/backend-config.json new file mode 100644 index 0000000..c001bf8 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/backend-config.json @@ -0,0 +1,78 @@ +{ + "auth": { + "geofencecontrolmap77dc1a87": { + "service": "Cognito", + "providerPlugin": "awscloudformation", + "dependsOn": [], + "customAuth": false, + "frontendAuthConfig": { + "socialProviders": [], + "usernameAttributes": [], + "signupAttributes": [ + "EMAIL" + ], + "passwordProtectionSettings": { + "passwordPolicyMinLength": 8, + "passwordPolicyCharacters": [] + }, + "mfaConfiguration": "OFF", + "mfaTypes": [ + "SMS" + ], + "verificationMechanisms": [ + "EMAIL" + ] + } + }, + "userPoolGroups": { + "service": "Cognito-UserPool-Groups", + "providerPlugin": "awscloudformation", + "dependsOn": [ + { + "category": "auth", + "resourceName": "geofencecontrolmap77dc1a87", + "attributes": [ + "UserPoolId", + "AppClientIDWeb", + "AppClientID", + "IdentityPoolId" + ] + } + ] + } + }, + "geo": { + "map51e71ba7": { + "isDefault": true, + "providerPlugin": "awscloudformation", + "service": "Map", + "mapStyle": "VectorEsriStreets", + "pricingPlan": "RequestBasedUsage", + "accessType": "AuthorizedAndGuestUsers" + }, + "geofenceCollection3b002ef5": { + "isDefault": true, + "providerPlugin": "awscloudformation", + "service": "GeofenceCollection", + "dataProvider": "Esri", + "pricingPlan": "RequestBasedUsage", + "accessType": "CognitoGroups", + "dependsOn": [ + { + "category": "auth", + "resourceName": "geofencecontrolmap77dc1a87", + "attributes": [ + "UserPoolId" + ] + }, + { + "category": "auth", + "resourceName": "userPoolGroups", + "attributes": [ + "geofenceAdminGroupRole" + ] + } + ] + } + } +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/geofence-collection-params.json b/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/geofence-collection-params.json new file mode 100644 index 0000000..282a288 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/geofence-collection-params.json @@ -0,0 +1,10 @@ +{ + "groupPermissions": { + "geofenceAdmin": [ + "Read geofence", + "Create/Update geofence", + "Delete geofence", + "List geofences" + ] + } +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/geofenceCollection3b002ef5-cloudformation-template.json b/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/geofenceCollection3b002ef5-cloudformation-template.json new file mode 100644 index 0000000..b4f8dd8 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/geofenceCollection3b002ef5-cloudformation-template.json @@ -0,0 +1,375 @@ +{ + "Mappings": { + "RegionMapping": { + "us-east-1": { + "locationServiceRegion": "us-east-1" + }, + "us-east-2": { + "locationServiceRegion": "us-east-2" + }, + "us-west-2": { + "locationServiceRegion": "us-west-2" + }, + "ap-southeast-1": { + "locationServiceRegion": "ap-southeast-1" + }, + "ap-southeast-2": { + "locationServiceRegion": "ap-southeast-2" + }, + "ap-northeast-1": { + "locationServiceRegion": "ap-northeast-1" + }, + "eu-central-1": { + "locationServiceRegion": "eu-central-1" + }, + "eu-north-1": { + "locationServiceRegion": "eu-north-1" + }, + "eu-west-1": { + "locationServiceRegion": "eu-west-1" + }, + "sa-east-1": { + "locationServiceRegion": "us-east-1" + }, + "ca-central-1": { + "locationServiceRegion": "us-east-1" + }, + "us-west-1": { + "locationServiceRegion": "us-west-2" + }, + "cn-north-1": { + "locationServiceRegion": "us-west-2" + }, + "cn-northwest-1": { + "locationServiceRegion": "us-west-2" + }, + "ap-south-1": { + "locationServiceRegion": "us-west-2" + }, + "ap-northeast-3": { + "locationServiceRegion": "us-west-2" + }, + "ap-northeast-2": { + "locationServiceRegion": "us-west-2" + }, + "eu-west-2": { + "locationServiceRegion": "eu-west-1" + }, + "eu-west-3": { + "locationServiceRegion": "eu-west-1" + }, + "me-south-1": { + "locationServiceRegion": "ap-southeast-1" + } + } + }, + "Parameters": { + "authuserPoolGroupsgeofenceAdminGroupRole": { + "Type": "String" + }, + "authgeofencecontrolmap77dc1a87UserPoolId": { + "Type": "String" + }, + "collectionName": { + "Type": "String" + }, + "dataProvider": { + "Type": "String" + }, + "pricingPlan": { + "Type": "String" + }, + "env": { + "Type": "String" + }, + "isDefault": { + "Type": "String" + } + }, + "Resources": { + "CustomGeofenceCollectionLambdaServiceRole9040D551": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "CustomGeofenceCollectionLambdaServiceRoleDefaultPolicy0A18B369": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "geo:CreateGeofenceCollection", + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": [ + "geo:UpdateGeofenceCollection", + "geo:DeleteGeofenceCollection" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": [ + "arn:aws:geo:${region}:${account}:geofence-collection/${collectionName}", + { + "region": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + }, + "account": { + "Ref": "AWS::AccountId" + }, + "collectionName": { + "Fn::Join": [ + "-", + [ + { + "Ref": "collectionName" + }, + { + "Ref": "env" + } + ] + ] + } + } + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "CustomGeofenceCollectionLambdaServiceRoleDefaultPolicy0A18B369", + "Roles": [ + { + "Ref": "CustomGeofenceCollectionLambdaServiceRole9040D551" + } + ] + } + }, + "CustomGeofenceCollectionLambdaCA3D002B": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "const response = require('cfn-response');\nconst aws = require('aws-sdk');\nexports.handler = async function (event, context) {\n try {\n console.log('REQUEST RECEIVED:' + JSON.stringify(event));\n if (event.RequestType == 'Create') {\n const params = {\n CollectionName: event.ResourceProperties.collectionName,\n PricingPlan: event.ResourceProperties.pricingPlan\n };\n if (params.PricingPlan !== 'RequestBasedUsage') {\n params['PricingPlanDataSource'] = event.ResourceProperties.dataSource;\n }\n const locationClient = new aws.Location({ apiVersion: '2020-11-19', region: event.ResourceProperties.region });\n const res = await locationClient.createGeofenceCollection(params).promise();\n console.log('create resource response data' + JSON.stringify(res));\n if (res.CollectionName && res.CollectionArn) {\n await response.send(event, context, response.SUCCESS, res, params.CollectionName);\n } else {\n await response.send(event, context, response.FAILED, res, params.CollectionName);\n }\n }\n if (event.RequestType == 'Update') {\n const params = {\n CollectionName: event.ResourceProperties.collectionName,\n PricingPlan: event.ResourceProperties.pricingPlan\n };\n if (params.PricingPlan !== 'RequestBasedUsage') {\n params['PricingPlanDataSource'] = event.ResourceProperties.dataSource;\n }\n const locationClient = new aws.Location({ apiVersion: '2020-11-19', region: event.ResourceProperties.region });\n const res = await locationClient.updateGeofenceCollection(params).promise();\n console.log('update resource response data' + JSON.stringify(res));\n if (res.CollectionName) {\n await response.send(event, context, response.SUCCESS, res, params.CollectionName);\n } else {\n await response.send(event, context, response.FAILED, res, params.CollectionName);\n }\n }\n if (event.RequestType == 'Delete') {\n const params = {\n CollectionName: event.ResourceProperties.collectionName\n };\n const locationClient = new aws.Location({ apiVersion: '2020-11-19', region: event.ResourceProperties.region });\n const res = await locationClient.deleteGeofenceCollection(params).promise();\n console.log('delete resource response data' + JSON.stringify(res));\n await response.send(event, context, response.SUCCESS, res, params.CollectionName);\n }\n } catch (err) {\n console.log(err.stack);\n const res = { Error: err };\n await response.send(event, context, response.FAILED, res, event.ResourceProperties.collectionName);\n throw err;\n }\n};\n" + }, + "Role": { + "Fn::GetAtt": [ + "CustomGeofenceCollectionLambdaServiceRole9040D551", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "nodejs14.x", + "Timeout": 300 + }, + "DependsOn": [ + "CustomGeofenceCollectionLambdaServiceRoleDefaultPolicy0A18B369", + "CustomGeofenceCollectionLambdaServiceRole9040D551" + ] + }, + "CustomGeofenceCollection": { + "Type": "Custom::LambdaCallout", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomGeofenceCollectionLambdaCA3D002B", + "Arn" + ] + }, + "collectionName": { + "Fn::Join": [ + "-", + [ + { + "Ref": "collectionName" + }, + { + "Ref": "env" + } + ] + ] + }, + "dataSource": { + "Ref": "dataProvider" + }, + "pricingPlan": { + "Ref": "pricingPlan" + }, + "region": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + }, + "env": { + "Ref": "env" + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "geofenceAdminGeofenceCollectionPolicy": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:GetGeofence", + "geo:PutGeofence", + "geo:BatchPutGeofence", + "geo:BatchDeleteGeofence", + "geo:ListGeofences" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": [ + "arn:aws:geo:${region}:${account}:geofence-collection/${collectionName}", + { + "region": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + }, + "account": { + "Ref": "AWS::AccountId" + }, + "collectionName": { + "Fn::GetAtt": [ + "CustomGeofenceCollection", + "CollectionName" + ] + } + } + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": { + "Fn::Join": [ + "", + [ + "geofenceAdmin", + { + "Fn::Join": [ + "-", + [ + { + "Ref": "collectionName" + }, + { + "Ref": "env" + } + ] + ] + }, + "Policy" + ] + ] + }, + "Roles": [ + { + "Fn::Join": [ + "-", + [ + { + "Ref": "authgeofencecontrolmap77dc1a87UserPoolId" + }, + "geofenceAdminGroupRole" + ] + ] + } + ] + } + } + }, + "Outputs": { + "Name": { + "Value": { + "Fn::GetAtt": [ + "CustomGeofenceCollection", + "CollectionName" + ] + } + }, + "Region": { + "Value": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + } + }, + "Arn": { + "Value": { + "Fn::Sub": [ + "arn:aws:geo:${region}:${account}:geofence-collection/${collectionName}", + { + "region": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + }, + "account": { + "Ref": "AWS::AccountId" + }, + "collectionName": { + "Fn::GetAtt": [ + "CustomGeofenceCollection", + "CollectionName" + ] + } + } + ] + } + } + } +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/parameters.json b/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/parameters.json new file mode 100644 index 0000000..3616de3 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/geo/geofenceCollection3b002ef5/parameters.json @@ -0,0 +1,6 @@ +{ + "collectionName": "geofenceCollection3b002ef5", + "dataProvider": "Esri", + "pricingPlan": "RequestBasedUsage", + "isDefault": true +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/geo/map51e71ba7/map51e71ba7-cloudformation-template.json b/samples/react/geo/geofence-control-map/amplify/backend/geo/map51e71ba7/map51e71ba7-cloudformation-template.json new file mode 100644 index 0000000..9fc9ff9 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/geo/map51e71ba7/map51e71ba7-cloudformation-template.json @@ -0,0 +1,336 @@ +{ + "Mappings": { + "RegionMapping": { + "us-east-1": { + "locationServiceRegion": "us-east-1" + }, + "us-east-2": { + "locationServiceRegion": "us-east-2" + }, + "us-west-2": { + "locationServiceRegion": "us-west-2" + }, + "ap-southeast-1": { + "locationServiceRegion": "ap-southeast-1" + }, + "ap-southeast-2": { + "locationServiceRegion": "ap-southeast-2" + }, + "ap-northeast-1": { + "locationServiceRegion": "ap-northeast-1" + }, + "eu-central-1": { + "locationServiceRegion": "eu-central-1" + }, + "eu-north-1": { + "locationServiceRegion": "eu-north-1" + }, + "eu-west-1": { + "locationServiceRegion": "eu-west-1" + }, + "sa-east-1": { + "locationServiceRegion": "us-east-1" + }, + "ca-central-1": { + "locationServiceRegion": "us-east-1" + }, + "us-west-1": { + "locationServiceRegion": "us-west-2" + }, + "cn-north-1": { + "locationServiceRegion": "us-west-2" + }, + "cn-northwest-1": { + "locationServiceRegion": "us-west-2" + }, + "ap-south-1": { + "locationServiceRegion": "us-west-2" + }, + "ap-northeast-3": { + "locationServiceRegion": "us-west-2" + }, + "ap-northeast-2": { + "locationServiceRegion": "us-west-2" + }, + "eu-west-2": { + "locationServiceRegion": "eu-west-1" + }, + "eu-west-3": { + "locationServiceRegion": "eu-west-1" + }, + "me-south-1": { + "locationServiceRegion": "ap-southeast-1" + } + } + }, + "Parameters": { + "authRoleName": { + "Type": "String" + }, + "unauthRoleName": { + "Type": "String" + }, + "mapName": { + "Type": "String" + }, + "mapStyle": { + "Type": "String" + }, + "pricingPlan": { + "Type": "String" + }, + "env": { + "Type": "String" + }, + "isDefault": { + "Type": "String" + } + }, + "Resources": { + "CustomMapLambdaServiceRole4EE7732C": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "CustomMapLambdaServiceRoleDefaultPolicy983FDD4E": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "geo:CreateMap", + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": [ + "geo:UpdateMap", + "geo:DeleteMap" + ], + "Effect": "Allow", + "Resource": { + "Fn::Sub": [ + "arn:aws:geo:${region}:${account}:map/${mapName}", + { + "region": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + }, + "account": { + "Ref": "AWS::AccountId" + }, + "mapName": { + "Fn::Join": [ + "-", + [ + { + "Ref": "mapName" + }, + { + "Ref": "env" + } + ] + ] + } + } + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "CustomMapLambdaServiceRoleDefaultPolicy983FDD4E", + "Roles": [ + { + "Ref": "CustomMapLambdaServiceRole4EE7732C" + } + ] + } + }, + "CustomMapLambda51D5D430": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "const response = require('cfn-response');\nconst aws = require('aws-sdk');\nexports.handler = async function (event, context) {\n try {\n console.log('REQUEST RECEIVED:' + JSON.stringify(event));\n if (event.RequestType == 'Create') {\n let params = {\n MapName: event.ResourceProperties.mapName,\n Configuration: {\n Style: event.ResourceProperties.mapStyle,\n },\n PricingPlan: event.ResourceProperties.pricingPlan,\n };\n const locationClient = new aws.Location({ apiVersion: '2020-11-19', region: event.ResourceProperties.region });\n const res = await locationClient.createMap(params).promise();\n console.log('create resource response data' + JSON.stringify(res));\n if (res.MapName && res.MapArn) {\n await response.send(event, context, response.SUCCESS, res, params.MapName);\n } else {\n await response.send(event, context, response.FAILED, res, params.MapName);\n }\n }\n if (event.RequestType == 'Update') {\n let params = {\n MapName: event.ResourceProperties.mapName,\n PricingPlan: event.ResourceProperties.pricingPlan,\n };\n const locationClient = new aws.Location({ apiVersion: '2020-11-19', region: event.ResourceProperties.region });\n const res = await locationClient.updateMap(params).promise();\n console.log('update resource response data' + JSON.stringify(res));\n if (res.MapName && res.MapArn) {\n await response.send(event, context, response.SUCCESS, res, params.MapName);\n } else {\n await response.send(event, context, response.FAILED, res, params.MapName);\n }\n }\n if (event.RequestType == 'Delete') {\n let params = {\n MapName: event.ResourceProperties.mapName,\n };\n const locationClient = new aws.Location({ apiVersion: '2020-11-19', region: event.ResourceProperties.region });\n const res = await locationClient.deleteMap(params).promise();\n console.log('delete resource response data' + JSON.stringify(res));\n await response.send(event, context, response.SUCCESS, res, params.MapName);\n }\n } catch (err) {\n console.log(err.stack);\n const res = { Error: err };\n await response.send(event, context, response.FAILED, res, event.ResourceProperties.mapName);\n throw err;\n }\n};\n" + }, + "Role": { + "Fn::GetAtt": [ + "CustomMapLambdaServiceRole4EE7732C", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "nodejs14.x", + "Timeout": 300 + }, + "DependsOn": [ + "CustomMapLambdaServiceRoleDefaultPolicy983FDD4E", + "CustomMapLambdaServiceRole4EE7732C" + ] + }, + "CustomMap": { + "Type": "Custom::LambdaCallout", + "Properties": { + "ServiceToken": { + "Fn::GetAtt": [ + "CustomMapLambda51D5D430", + "Arn" + ] + }, + "mapName": { + "Fn::Join": [ + "-", + [ + { + "Ref": "mapName" + }, + { + "Ref": "env" + } + ] + ] + }, + "mapStyle": { + "Ref": "mapStyle" + }, + "pricingPlan": { + "Ref": "pricingPlan" + }, + "region": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + }, + "env": { + "Ref": "env" + } + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + }, + "MapPolicy": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "geo:GetMapStyleDescriptor", + "geo:GetMapGlyphs", + "geo:GetMapSprites", + "geo:GetMapTile" + ], + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "CustomMap", + "MapArn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": { + "Fn::Join": [ + "", + [ + { + "Fn::Join": [ + "-", + [ + { + "Ref": "mapName" + }, + { + "Ref": "env" + } + ] + ] + }, + "Policy" + ] + ] + }, + "Roles": [ + { + "Ref": "authRoleName" + }, + { + "Ref": "unauthRoleName" + } + ] + } + } + }, + "Outputs": { + "Name": { + "Value": { + "Fn::GetAtt": [ + "CustomMap", + "MapName" + ] + } + }, + "Style": { + "Value": { + "Ref": "mapStyle" + } + }, + "Region": { + "Value": { + "Fn::FindInMap": [ + "RegionMapping", + { + "Ref": "AWS::Region" + }, + "locationServiceRegion" + ] + } + }, + "Arn": { + "Value": { + "Fn::GetAtt": [ + "CustomMap", + "MapArn" + ] + } + } + }, + "Description": "{\"createdOn\":\"Mac\",\"createdBy\":\"Amplify\",\"createdWith\":\"7.3.2-geo.2\",\"stackType\":\"geo-Map\",\"metadata\":{}}" +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/geo/map51e71ba7/parameters.json b/samples/react/geo/geofence-control-map/amplify/backend/geo/map51e71ba7/parameters.json new file mode 100644 index 0000000..08b8881 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/geo/map51e71ba7/parameters.json @@ -0,0 +1,12 @@ +{ + "authRoleName": { + "Ref": "AuthRoleName" + }, + "unauthRoleName": { + "Ref": "UnauthRoleName" + }, + "mapName": "map51e71ba7", + "mapStyle": "VectorEsriStreets", + "pricingPlan": "RequestBasedUsage", + "isDefault": true +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/tags.json b/samples/react/geo/geofence-control-map/amplify/backend/tags.json new file mode 100644 index 0000000..b9321d7 --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/tags.json @@ -0,0 +1,10 @@ +[ + { + "Key": "user:Stack", + "Value": "{project-env}" + }, + { + "Key": "user:Application", + "Value": "{project-name}" + } +] \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/backend/types/amplify-dependent-resources-ref.d.ts b/samples/react/geo/geofence-control-map/amplify/backend/types/amplify-dependent-resources-ref.d.ts new file mode 100644 index 0000000..555079e --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/backend/types/amplify-dependent-resources-ref.d.ts @@ -0,0 +1,29 @@ +export type AmplifyDependentResourcesAttributes = { + "auth": { + "geofencecontrolmap77dc1a87": { + "IdentityPoolId": "string", + "IdentityPoolName": "string", + "UserPoolId": "string", + "UserPoolArn": "string", + "UserPoolName": "string", + "AppClientIDWeb": "string", + "AppClientID": "string" + }, + "userPoolGroups": { + "geofenceAdminGroupRole": "string" + } + }, + "geo": { + "map51e71ba7": { + "Name": "string", + "Style": "string", + "Region": "string", + "Arn": "string" + }, + "geofenceCollection3b002ef5": { + "Name": "string", + "Region": "string", + "Arn": "string" + } + } +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/cli.json b/samples/react/geo/geofence-control-map/amplify/cli.json new file mode 100644 index 0000000..455c9db --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/cli.json @@ -0,0 +1,51 @@ +{ + "features": { + "graphqltransformer": { + "addmissingownerfields": true, + "improvepluralization": false, + "validatetypenamereservedwords": true, + "useexperimentalpipelinedtransformer": false, + "enableiterativegsiupdates": true, + "secondarykeyasgsi": true, + "skipoverridemutationinputtypes": true, + "transformerversion": 1, + "suppressschemamigrationprompt": true + }, + "frontend-ios": { + "enablexcodeintegration": true + }, + "auth": { + "enablecaseinsensitivity": true, + "useinclusiveterminology": true, + "breakcirculardependency": true, + "forcealiasattributes": false, + "useenabledmfas": true + }, + "codegen": { + "useappsyncmodelgenplugin": true, + "usedocsgeneratorplugin": true, + "usetypesgeneratorplugin": true, + "cleangeneratedmodelsdirectory": true, + "retaincasestyle": true, + "addtimestampfields": true, + "handlelistnullabilitytransparently": true, + "emitauthprovider": true, + "generateindexrules": true, + "enabledartnullsafety": true + }, + "appsync": { + "generategraphqlpermissions": true + }, + "latestregionsupport": { + "pinpoint": 1, + "translate": 1, + "transcribe": 1, + "rekognition": 1, + "textract": 1, + "comprehend": 1 + }, + "project": { + "overrides": true + } + } +} \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/amplify/hooks/README.md b/samples/react/geo/geofence-control-map/amplify/hooks/README.md new file mode 100644 index 0000000..8fb601e --- /dev/null +++ b/samples/react/geo/geofence-control-map/amplify/hooks/README.md @@ -0,0 +1,7 @@ +# Command Hooks + +Command hooks can be used to run custom scripts upon Amplify CLI lifecycle events like pre-push, post-add-function, etc. + +To get started, add your script files based on the expected naming convention in this directory. + +Learn more about the script file naming convention, hook parameters, third party dependencies, and advanced configurations at https://docs.amplify.aws/cli/usage/command-hooks diff --git a/samples/react/geo/geofence-control-map/package.json b/samples/react/geo/geofence-control-map/package.json new file mode 100644 index 0000000..43071a5 --- /dev/null +++ b/samples/react/geo/geofence-control-map/package.json @@ -0,0 +1,42 @@ +{ + "name": "geofence-control-map", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^5.11.4", + "@testing-library/react": "^11.1.0", + "@testing-library/user-event": "^12.1.10", + "aws-amplify": "geo", + "aws-amplify-react": "^5.1.9", + "maplibre-gl": "1", + "maplibre-gl-js-amplify": "geo", + "react": "^17.0.2", + "react-dom": "^17.0.2", + "react-scripts": "4.0.3", + "web-vitals": "^1.0.1" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/samples/react/geo/geofence-control-map/public/favicon.ico b/samples/react/geo/geofence-control-map/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/samples/react/geo/geofence-control-map/public/favicon.ico differ diff --git a/samples/react/geo/geofence-control-map/public/index.html b/samples/react/geo/geofence-control-map/public/index.html new file mode 100644 index 0000000..aa069f2 --- /dev/null +++ b/samples/react/geo/geofence-control-map/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/samples/react/geo/geofence-control-map/public/logo192.png b/samples/react/geo/geofence-control-map/public/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/samples/react/geo/geofence-control-map/public/logo192.png differ diff --git a/samples/react/geo/geofence-control-map/public/logo512.png b/samples/react/geo/geofence-control-map/public/logo512.png new file mode 100644 index 0000000..a4e47a6 Binary files /dev/null and b/samples/react/geo/geofence-control-map/public/logo512.png differ diff --git a/samples/react/geo/geofence-control-map/public/manifest.json b/samples/react/geo/geofence-control-map/public/manifest.json new file mode 100644 index 0000000..080d6c7 --- /dev/null +++ b/samples/react/geo/geofence-control-map/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/samples/react/geo/geofence-control-map/public/robots.txt b/samples/react/geo/geofence-control-map/public/robots.txt new file mode 100644 index 0000000..e9e57dc --- /dev/null +++ b/samples/react/geo/geofence-control-map/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/samples/react/geo/geofence-control-map/src/App.css b/samples/react/geo/geofence-control-map/src/App.css new file mode 100644 index 0000000..d413d74 --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/App.css @@ -0,0 +1,7 @@ +#map { + /* The id of the container you passed to createMap */ + position: absolute; + top: 0; + bottom: 0; + width: 100%; +} diff --git a/samples/react/geo/geofence-control-map/src/App.js b/samples/react/geo/geofence-control-map/src/App.js new file mode 100644 index 0000000..e71172e --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/App.js @@ -0,0 +1,37 @@ +import { useEffect } from 'react'; +import { createMap, AmplifyGeofenceControl } from 'maplibre-gl-js-amplify'; +import { withAuthenticator } from 'aws-amplify-react'; // or 'aws-amplify-react-native'; +import 'maplibre-gl/dist/maplibre-gl.css'; +import config from './aws-exports'; +import Amplify from 'aws-amplify'; +import './App.css'; +import '@aws-amplify/ui/dist/style.css'; + +Amplify.configure(config); + +function App() { + useEffect(() => { + async function initializeMap() { + const map = await createMap({ + container: 'map', + center: [-122.431297, 37.773972], + zoom: 11, + }); + + const control = new AmplifyGeofenceControl(); + map.addControl(control); + + map.on('idle', function() { + if (window.Cypress) { + window.map = map; // Add map to window so that our tests have access to the maplibre map + window.appReady = true; // Signal to cypress test runner to start + } + }); + } + initializeMap(); + }, []); + + return
; +} + +export default withAuthenticator(App); diff --git a/samples/react/geo/geofence-control-map/src/App.test.js b/samples/react/geo/geofence-control-map/src/App.test.js new file mode 100644 index 0000000..1f03afe --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/App.test.js @@ -0,0 +1,8 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/samples/react/geo/geofence-control-map/src/index.css b/samples/react/geo/geofence-control-map/src/index.css new file mode 100644 index 0000000..ec2585e --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/index.css @@ -0,0 +1,13 @@ +body { + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/samples/react/geo/geofence-control-map/src/index.js b/samples/react/geo/geofence-control-map/src/index.js new file mode 100644 index 0000000..ef2edf8 --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/index.js @@ -0,0 +1,17 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +ReactDOM.render( + + + , + document.getElementById('root') +); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/samples/react/geo/geofence-control-map/src/logo.svg b/samples/react/geo/geofence-control-map/src/logo.svg new file mode 100644 index 0000000..9dfc1c0 --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/samples/react/geo/geofence-control-map/src/reportWebVitals.js b/samples/react/geo/geofence-control-map/src/reportWebVitals.js new file mode 100644 index 0000000..5253d3a --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/samples/react/geo/geofence-control-map/src/setupTests.js b/samples/react/geo/geofence-control-map/src/setupTests.js new file mode 100644 index 0000000..8f2609b --- /dev/null +++ b/samples/react/geo/geofence-control-map/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom';