From 2d4430bef51d8895aaf84ef19f103a014dc2303c Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:00:03 +0100 Subject: [PATCH 01/15] eslint rule fix --- examples/terms-modal-banner-s3/.gitignore | 146 +++++++++++++ examples/terms-modal-banner-s3/README.md | 109 ++++++++++ .../terms-modal-banner-s3/app-manifest.yaml | 8 + .../terms-modal-banner-s3/getSignedURL/app.js | 52 +++++ .../getSignedURL/package.json | 15 ++ examples/terms-modal-banner-s3/template.yaml | 186 ++++++++++++++++ .../terms-modal-banner-s3/webassets/app.html | 127 +++++++++++ .../webassets/modal.html | 199 ++++++++++++++++++ .../webassets/variables.js | 17 ++ 9 files changed, 859 insertions(+) create mode 100644 examples/terms-modal-banner-s3/.gitignore create mode 100644 examples/terms-modal-banner-s3/README.md create mode 100644 examples/terms-modal-banner-s3/app-manifest.yaml create mode 100644 examples/terms-modal-banner-s3/getSignedURL/app.js create mode 100644 examples/terms-modal-banner-s3/getSignedURL/package.json create mode 100644 examples/terms-modal-banner-s3/template.yaml create mode 100644 examples/terms-modal-banner-s3/webassets/app.html create mode 100644 examples/terms-modal-banner-s3/webassets/modal.html create mode 100644 examples/terms-modal-banner-s3/webassets/variables.js diff --git a/examples/terms-modal-banner-s3/.gitignore b/examples/terms-modal-banner-s3/.gitignore new file mode 100644 index 000000000..d9b5e2934 --- /dev/null +++ b/examples/terms-modal-banner-s3/.gitignore @@ -0,0 +1,146 @@ + +# Created by https://www.gitignore.io/api/osx,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +# End of https://www.gitignore.io/api/osx,node,linux,windows + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +#AWS/SAM +.aws-sam +packaged.yaml +samconfig.toml + +#jbesw-specific +testData/ diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md new file mode 100644 index 000000000..152d8ef5e --- /dev/null +++ b/examples/terms-modal-banner-s3/README.md @@ -0,0 +1,109 @@ +# Miro Terms Modal Banner App (Web-SDK V2 & AWS S3) + +This app creates a custom modal banner on your Miro boards that you can show to your users/attendees with any desired content and/or call to actions. It is typically used to accept terms and agreements before using a Miro board. + + To understand how to set up the app (including AWS resources needed to run the app) see the +[developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-s3) on Miro's Developer documentation. + +💸 **Important**: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. 💸 + +# 👨🏻‍💻 App Demo + +![terms-modal-banner-s3-demo](https://github.com/horeaporutiu/app-examples-template/assets/10428517/98c2c5c6-d89c-4b00-8bbf-d6fd40bda284) + +# 📒 Table of Contents + +- [Support](#support) +- [Included Features](#features) +- [Tools and Technologies](#tools) +- [Prerequisites](#prerequisites) +- [Associated Developer Tutorial](#tutorial) +- [Run the app locally](#run) +- [Folder Structure](#folder) +- [Contributing](#contributing) +- [License](#license) + +# 🙋🏻 Support + +If you have any questions or need assistance setting up this application, please reach out to your Miro Customer Success Manager or dedicated Miro Solutions Engineer. + +# ⚙️ Included Features + +- [Miro Web SDK](https://developers.miro.com/docs/web-sdk-reference) + - [miro.board.ui.canOpenModal()](https://developers.miro.com/docs/websdk-reference-ui#canopenmodal) + - [miro.board.ui.openModal()](https://developers.miro.com/docs/websdk-reference-ui#openmodal) + +# 🛠️ Tools and Technologies + +- [AWS CLI](https://aws.amazon.com/cli/) +- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) +- [AWS CloudFormation](https://aws.amazon.com/cloudformation/) +- [AWS S3](https://react.dev/) +- [AWS Lambda](https://react.dev/) +- [AWS API Gateway](https://aws.amazon.com/api-gateway/) + +# ✅ Prerequisites + +- You have a [Miro account](https://miro.com/signup/). +- You're [signed in to Miro](https://miro.com/login/). +- Your Miro account has a [Developer team](https://developers.miro.com/docs/create-a-developer-team). +- [NodeJS 16.x installed](https://nodejs.org/en/download/) +- [AWS CLI](https://aws.amazon.com/cli/) already configured with Administrator permission +- [AWS SAM CLI installed](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - minimum version 0.48. + +# 📖 Associated Developer Tutorial + +Using AWS S3 you can host your html files and serve them as regular web pages so they can load within Miro. In addition, you can also use AWS S3 to add custom functionality to your Miro app to track which users have already accepted the modal, so that the modal does not re-appear again for those users. In this guide we will guide you on how to achieve this functionality using Miro and AWS S3. + +> See the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-s3) on Miro's Developer documentation. + +# 🏃🏽‍♂️ Run the app using AWS S3 + +Once you have finished all of the steps related to AWS in the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-s3), you can then create the Miro app. + +1. In your new Miro app settings, add in the `App URL`. It should end with `webassets/app.html`. +2. Open the [app manifest editor](https://developers.miro.com/docs/manually-create-an-app#step-2-configure-your-app-in-miro) by clicking **Edit in Manifest**. \ + In the app manifest editor, configure the app as follows ⚠️ Note: you will need to change your sdkUri to be your app.html which is hosted in the `webassets` folder of your S3 bucket. Mine is just shown as an example and then click save: + +```yaml +# See https://developers.miro.com/docs/app-manifest on how to use this +appName: s3-modal-banner +sdkVersion: SDK_V2 +sdkUri: >- + https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.amazonaws.com/webassets/app.html +scopes: + - identity:read +``` + +3. Go back to your app home page, and under the `Permissions` section, you will see a blue button that says `Install app and get OAuth token`. Click that button. Then click on `Add` as shown in the video below. In the video we install a different app, but the process is the same regardless of the app. + +> ⚠️ We recommend to install your app on a [developer team](https://developers.miro.com/docs/create-a-developer-team) while you are developing or testing apps.⚠️ + +https://github.com/miroapp/app-examples/assets/10428517/1e6862de-8617-46ef-b265-97ff1cbfe8bf + +4. Go to the team in which you installed the app, and open a board. +5. Once you open the board, the modal should appear within a few seconds. +6. If you click accept, you should see a checkmark and then you should not see the modal again when refreshing the page or opening a new board + on that team. +7. You can also check your AWS S3 bucket and see that a new folder `users` has been added. The userID of the user which clicked on `accept` will + be added to the `users` folder in AWS S3. + +🎉 That's it. Great job! 🎉 + +# 🗂️ Folder structure + +``` +. +├── webassets <-- HTML and JavaScript files for the Miro app +├── getSignedURL <-- Source code for the serverless backend +├── samconfig.toml <-- Configuration code for AWS SAM (AWS Serverless Application Model) +├── template.yaml <-- The yaml code used to generate AWS resources via AWS SAM. +``` + +# 🫱🏻‍🫲🏽 Contributing + +If you want to contribute to this example, or any other Miro Open Source project, please review [Miro's contributing guide](https://github.com/miroapp/app-examples/blob/main/CONTRIBUTING.md). + +# 🪪 License + +[MIT License](https://github.com/miroapp/app-examples/blob/main/LICENSE). diff --git a/examples/terms-modal-banner-s3/app-manifest.yaml b/examples/terms-modal-banner-s3/app-manifest.yaml new file mode 100644 index 000000000..8f8814706 --- /dev/null +++ b/examples/terms-modal-banner-s3/app-manifest.yaml @@ -0,0 +1,8 @@ +# See https://developers.miro.com/docs/app-manifest on how to use this +# make sure to replace the sdkUri with the correct URL (it will be different for each deployment) +appName: s3-modal-banner +sdkVersion: SDK_V2 +sdkUri: >- + https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.amazonaws.com/webassets/app.html +scopes: + - identity:read diff --git a/examples/terms-modal-banner-s3/getSignedURL/app.js b/examples/terms-modal-banner-s3/getSignedURL/app.js new file mode 100644 index 000000000..4548993c5 --- /dev/null +++ b/examples/terms-modal-banner-s3/getSignedURL/app.js @@ -0,0 +1,52 @@ +/* + Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + Permission is hereby granted, free of charge, to any person obtaining a copy of this + software and associated documentation files (the "Software"), to deal in the Software + without restriction, including without limitation the rights to use, copy, modify, + merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A + PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +"use strict"; + +const AWS = require("aws-sdk"); +AWS.config.update({ region: process.env.AWS_REGION }); +const s3 = new AWS.S3({ + apiVersion: "2006-03-01", + signatureVersion: "v4", +}); + +// Change this value to adjust the signed URL's expiration +const URL_EXPIRATION_SECONDS = 300; + +// Main Lambda entry point +exports.handler = async (event) => { + return await getUploadURL(event); +}; + +const getUploadURL = async function (event) { + const userID = event.queryStringParameters.id; + const Key = userID; + + // Get signed URL from S3 + const s3Params = { + Bucket: process.env.MiroBannerAccepters + "/users", + Key, + Expires: URL_EXPIRATION_SECONDS, + ContentType: "text/plain", + }; + + console.log("Params: ", s3Params); + const uploadURL = await s3.getSignedUrlPromise("putObject", s3Params); + + return JSON.stringify({ + uploadURL: uploadURL, + Key, + }); +}; diff --git a/examples/terms-modal-banner-s3/getSignedURL/package.json b/examples/terms-modal-banner-s3/getSignedURL/package.json new file mode 100644 index 000000000..83453a499 --- /dev/null +++ b/examples/terms-modal-banner-s3/getSignedURL/package.json @@ -0,0 +1,15 @@ +{ + "name": "miro-terms-banner-s3-uploader", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "James Beswick, AWS Serverless", + "license": "MIT-0", + "devDependencies": { + "aws-sdk": "^2.749.0" + } +} diff --git a/examples/terms-modal-banner-s3/template.yaml b/examples/terms-modal-banner-s3/template.yaml new file mode 100644 index 000000000..7fafdc5ec --- /dev/null +++ b/examples/terms-modal-banner-s3/template.yaml @@ -0,0 +1,186 @@ +AWSTemplateFormatVersion: 2010-09-09 +Transform: AWS::Serverless-2016-10-31 +Description: S3 Miro Banner Accepters + +Resources: + ## S3 bucket + S3MiroBannerAccepters: + Type: AWS::S3::Bucket + Properties: + BucketName: + !Join [ + "", + [ + "s3-", + !Join [ + "-", + [ + !Ref AWS::StackName, + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ], + ], + ] + CorsConfiguration: + CorsRules: + - AllowedHeaders: + - "*" + AllowedMethods: + - GET + - PUT + - HEAD + AllowedOrigins: + - !Join [ + "", + [ + "https://s3-", + !Join [ + "-", + [ + !Ref AWS::StackName, + !Select [ + 4, + !Split [ + "-", + !Select [2, !Split ["/", !Ref AWS::StackId]], + ], + ], + ], + ], + ".s3.", + !Ref AWS::Region, + ".amazonaws.com", + ], + ] + - !Join [ + "", + [ + "https://s3-", + !Join [ + "-", + [ + !Ref AWS::StackName, + !Select [ + 4, + !Split [ + "-", + !Select [2, !Split ["/", !Ref AWS::StackId]], + ], + ], + ], + ], + ".s3.amazonaws.com", + ], + ] + PublicAccessBlockConfiguration: + BlockPublicAcls: false + BlockPublicPolicy: false + IgnorePublicAcls: false + RestrictPublicBuckets: false + + ## This permission will make the contents of the S3 bucket publicly readable + ProductBucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Ref S3MiroBannerAccepters + PolicyDocument: + Id: PublicReadPolicy + Version: "2012-10-17" + Statement: + - Sid: PublicReadForGetBucketObjects + Effect: Allow + Principal: "*" + Action: s3:GetObject + Resource: !Sub "arn:aws:s3:::${S3MiroBannerAccepters}/*" + + # HTTP API + MiroBannerAPI: + Type: AWS::Serverless::HttpApi + Properties: + Name: + !Join [ + "", + [ + "api-", + !Join [ + "-", + [ + !Ref AWS::StackName, + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ], + ], + ] + Description: !Sub 'API endpoint for the "Miro Terms Modal app". It handles requests to write on the S3 bucket "${S3MiroBannerAccepters}/users"' + # CORS configuration - The s3 bucket origin will be added as the only allowed origin. + # See https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-httpapi-httpapicorsconfiguration.html + CorsConfiguration: + AllowMethods: + - GET + - OPTIONS + AllowHeaders: + - "*" + AllowOrigins: + - !Sub "https://${S3MiroBannerAccepters}.s3.${AWS::Region}.amazonaws.com" + - !Sub "https://${S3MiroBannerAccepters}.s3.amazonaws.com" + + ## Lambda function + MiroBannerAcceptersRequestFunction: + # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction + Type: AWS::Serverless::Function + Properties: + FunctionName: + !Join [ + "-", + [ + !Ref AWS::StackName, + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ] + Description: !Sub 'Lambda function for the "Miro Terms Modal app". It writes data on the S3 bucket "${S3MiroBannerAccepters}/users"' + CodeUri: getSignedURL/ + Handler: app.handler + Runtime: nodejs16.x + Timeout: 3 + MemorySize: 128 + Environment: + Variables: + MiroBannerAccepters: !Ref S3MiroBannerAccepters + Policies: + - S3WritePolicy: + BucketName: !Ref S3MiroBannerAccepters + ## This permission allows the Lambda function to request signed URLs + ## for objects that will be publicly readable. Uncomment if you want this ACL. + - Statement: + - Effect: Allow + Resource: !Sub "arn:aws:s3:::${S3MiroBannerAccepters}/" + Action: + - s3:putObjectAcl + Events: + UploadAssetAPI: + Type: HttpApi + Properties: + Path: /uploads + Method: get + ApiId: !Ref MiroBannerAPI + +## Take a note of the outputs for deploying the workflow templates in this sample application +Outputs: + S3RecordTermsAcceptanceEndpointUrl: + Description: "HTTP API endpoint URL to get the S3 signed URL to write on the S3 bucket" + Value: !Sub "https://${MiroBannerAPI}.execute-api.${AWS::Region}.amazonaws.com" + S3BucketName: + Description: "Name of the S3 bucket that captures users who have accepted the terms modal in Miro" + Value: !Ref S3MiroBannerAccepters + S3BucketBaseUrl: + Description: "Base URL of the S3 bucket - it will be used to query/read users who have already accepted the terms modal" + Value: !Sub "https://${S3MiroBannerAccepters}.s3.${AWS::Region}.amazonaws.com" diff --git a/examples/terms-modal-banner-s3/webassets/app.html b/examples/terms-modal-banner-s3/webassets/app.html new file mode 100644 index 000000000..603fce7a9 --- /dev/null +++ b/examples/terms-modal-banner-s3/webassets/app.html @@ -0,0 +1,127 @@ + + + + + + + + + + + diff --git a/examples/terms-modal-banner-s3/webassets/modal.html b/examples/terms-modal-banner-s3/webassets/modal.html new file mode 100644 index 000000000..3dbd60089 --- /dev/null +++ b/examples/terms-modal-banner-s3/webassets/modal.html @@ -0,0 +1,199 @@ + + + + + + + + + +
+
+
+ +
+ To use Company Inc.'s Miro boards, please accept the + Usage Policy.
+ Please reach out to your IT administrator for more information on + the security requirements for using Company Inc.'s Miro boards. +
+
+ + + +
+
+
+
+ + + + diff --git a/examples/terms-modal-banner-s3/webassets/variables.js b/examples/terms-modal-banner-s3/webassets/variables.js new file mode 100644 index 000000000..734d5c393 --- /dev/null +++ b/examples/terms-modal-banner-s3/webassets/variables.js @@ -0,0 +1,17 @@ +/* variables.js */ +/* eslint-disable no-unused-vars */ + +var MODAL_URL = + "https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.amazonaws.com/webassets/modal.html"; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com/webassets/modal.html';) + +var S3_RECORD_TERMS_ACCEPTANCE_ENDPOINT_URL = + "https://p4mgnq49fb.execute-api.us-east-1.amazonaws.com"; // keep the single quotes around the value (e.g. 'https://e4g624kyue.execute-api.eu-central-1.amazonaws.com';) + +var S3_BUCKET_BASE_URL = + "https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.us-east-1.amazonaws.com"; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com';) + +var SECONDS_TO_WAIT = 3; // Enter value as number (not string) - Enter value as number (not string) - This is the interval in seconds the app will check if the current user has accepted the terms modal. With the default value (3) the app will check every 3 seconds if the user has accepted the modal until the terms modal has been successfully accepted + +var MODAL_WITH = 590; // Enter value as number (not string) - Width of the modal pop-up in pixels - Adjust as desired + +var MODAL_HEIGHT = 300; // Enter value as number (not string) - Height of the modal pop-up in pixels - Adjusted as desired From d00e387c2c1d0101a4d8542bbb9414b4ca193ad5 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:00:56 +0100 Subject: [PATCH 02/15] add default variables file --- examples/terms-modal-banner-s3/webassets/variables.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/terms-modal-banner-s3/webassets/variables.js b/examples/terms-modal-banner-s3/webassets/variables.js index 734d5c393..a0563f0be 100644 --- a/examples/terms-modal-banner-s3/webassets/variables.js +++ b/examples/terms-modal-banner-s3/webassets/variables.js @@ -1,14 +1,13 @@ /* variables.js */ /* eslint-disable no-unused-vars */ -var MODAL_URL = - "https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.amazonaws.com/webassets/modal.html"; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com/webassets/modal.html';) +var MODAL_URL = 'replace with your "modal.html" URL from AWS S3'; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com/webassets/modal.html';) var S3_RECORD_TERMS_ACCEPTANCE_ENDPOINT_URL = - "https://p4mgnq49fb.execute-api.us-east-1.amazonaws.com"; // keep the single quotes around the value (e.g. 'https://e4g624kyue.execute-api.eu-central-1.amazonaws.com';) + 'replace with the value of "S3RecordTermsAcceptanceEndpointUrl" from your AWS SAM CLI Output'; // keep the single quotes around the value (e.g. 'https://e4g624kyue.execute-api.eu-central-1.amazonaws.com';) var S3_BUCKET_BASE_URL = - "https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.us-east-1.amazonaws.com"; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com';) + 'replace with the value of "S3BucketBaseUrl" from your AWS SAM CLI Output'; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com';) var SECONDS_TO_WAIT = 3; // Enter value as number (not string) - Enter value as number (not string) - This is the interval in seconds the app will check if the current user has accepted the terms modal. With the default value (3) the app will check every 3 seconds if the user has accepted the modal until the terms modal has been successfully accepted From de49599caf065a191ce4fa766a53dab0c18b7d98 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:01:49 +0100 Subject: [PATCH 03/15] add default app-manifest file --- examples/terms-modal-banner-s3/app-manifest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/terms-modal-banner-s3/app-manifest.yaml b/examples/terms-modal-banner-s3/app-manifest.yaml index 8f8814706..5fbf52eb0 100644 --- a/examples/terms-modal-banner-s3/app-manifest.yaml +++ b/examples/terms-modal-banner-s3/app-manifest.yaml @@ -3,6 +3,6 @@ appName: s3-modal-banner sdkVersion: SDK_V2 sdkUri: >- - https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.amazonaws.com/webassets/app.html + https://s3-miro-terms-banner-12345.s3.amazonaws.com/webassets/app.html scopes: - identity:read From 065180f08dd24928e6a1f9cba75a2c21c7b30773 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:05:48 +0100 Subject: [PATCH 04/15] adding app demo --- examples/terms-modal-banner-s3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md index 152d8ef5e..3b56708b9 100644 --- a/examples/terms-modal-banner-s3/README.md +++ b/examples/terms-modal-banner-s3/README.md @@ -9,7 +9,7 @@ This app creates a custom modal banner on your Miro boards that you can show to # 👨🏻‍💻 App Demo -![terms-modal-banner-s3-demo](https://github.com/horeaporutiu/app-examples-template/assets/10428517/98c2c5c6-d89c-4b00-8bbf-d6fd40bda284) +(https://github.com/miroapp/app-examples/assets/10428517/f75d4e56-cc2e-4e39-af40-7881326e99d0) # 📒 Table of Contents From 46a241bf368f6e7478d0734768f224ffb67e55ae Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:06:43 +0100 Subject: [PATCH 05/15] adding app demo --- examples/terms-modal-banner-s3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md index 3b56708b9..d47ddcef0 100644 --- a/examples/terms-modal-banner-s3/README.md +++ b/examples/terms-modal-banner-s3/README.md @@ -9,7 +9,7 @@ This app creates a custom modal banner on your Miro boards that you can show to # 👨🏻‍💻 App Demo -(https://github.com/miroapp/app-examples/assets/10428517/f75d4e56-cc2e-4e39-af40-7881326e99d0) +https://github.com/miroapp/app-examples/assets/10428517/f75d4e56-cc2e-4e39-af40-7881326e99d0 # 📒 Table of Contents From 63c83a73ccafb7528c3fc56b7c7d7726e02e1dce Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:11:44 +0100 Subject: [PATCH 06/15] adding app demo --- examples/terms-modal-banner-s3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md index d47ddcef0..2094f248b 100644 --- a/examples/terms-modal-banner-s3/README.md +++ b/examples/terms-modal-banner-s3/README.md @@ -70,7 +70,7 @@ Once you have finished all of the steps related to AWS in the [developer tutoria appName: s3-modal-banner sdkVersion: SDK_V2 sdkUri: >- - https://s3-miro-terms-banner-horea2-125b5310d8ef.s3.amazonaws.com/webassets/app.html + https://s3-miro-terms-banner-12345.s3.amazonaws.com/webassets/app.html scopes: - identity:read ``` From 929ce92e81d8b6dd227c93d402256e6d26e0d8be Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:16:33 +0100 Subject: [PATCH 07/15] adding app demo --- examples/terms-modal-banner-s3/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md index 2094f248b..841ff1607 100644 --- a/examples/terms-modal-banner-s3/README.md +++ b/examples/terms-modal-banner-s3/README.md @@ -94,9 +94,12 @@ https://github.com/miroapp/app-examples/assets/10428517/1e6862de-8617-46ef-b265- ``` . -├── webassets <-- HTML and JavaScript files for the Miro app -├── getSignedURL <-- Source code for the serverless backend -├── samconfig.toml <-- Configuration code for AWS SAM (AWS Serverless Application Model) +├── getSignedURL <-- Source code for the serverless backend. +│ └── app.js // The code to add userID to S3 bucket once user accepts terms. +├── webassets <-- HTML and JavaScript files for the Miro app. +│ ├── app.html // The code which uses Miro WebSDK to open the modal for the user. +│ └── modal.html // The code which serves as the UI for the terms which the user will accept. + ├── template.yaml <-- The yaml code used to generate AWS resources via AWS SAM. ``` From 9ef2c89381db1ea7047f5d1cc8553508d2f8385f Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:18:32 +0100 Subject: [PATCH 08/15] adding SDK methods --- examples/terms-modal-banner-s3/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md index 841ff1607..42e631518 100644 --- a/examples/terms-modal-banner-s3/README.md +++ b/examples/terms-modal-banner-s3/README.md @@ -32,6 +32,8 @@ If you have any questions or need assistance setting up this application, please - [Miro Web SDK](https://developers.miro.com/docs/web-sdk-reference) - [miro.board.ui.canOpenModal()](https://developers.miro.com/docs/websdk-reference-ui#canopenmodal) - [miro.board.ui.openModal()](https://developers.miro.com/docs/websdk-reference-ui#openmodal) + - [miro.board.ui.closeModal()](https://developers.miro.com/docs/websdk-reference-ui#closemodal) + - [miro.board.getUserInfo()](https://developers.miro.com/docs/websdk-reference-board#getuserinfo) # 🛠️ Tools and Technologies From afe264afbb5602a98437e0c6729a91184b614227 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Wed, 21 Feb 2024 10:56:25 +0100 Subject: [PATCH 09/15] adding install video --- examples/terms-modal-banner-s3/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md index 42e631518..506542a60 100644 --- a/examples/terms-modal-banner-s3/README.md +++ b/examples/terms-modal-banner-s3/README.md @@ -9,7 +9,7 @@ This app creates a custom modal banner on your Miro boards that you can show to # 👨🏻‍💻 App Demo -https://github.com/miroapp/app-examples/assets/10428517/f75d4e56-cc2e-4e39-af40-7881326e99d0 +https://github.com/miroapp/app-examples/assets/10428517/16e009f7-70f2-435b-bd61-f11845ad3197 # 📒 Table of Contents @@ -81,7 +81,7 @@ scopes: > ⚠️ We recommend to install your app on a [developer team](https://developers.miro.com/docs/create-a-developer-team) while you are developing or testing apps.⚠️ -https://github.com/miroapp/app-examples/assets/10428517/1e6862de-8617-46ef-b265-97ff1cbfe8bf +https://github.com/miroapp/app-examples/assets/10428517/43922ea1-d619-4480-af23-029a1a4e67d8 4. Go to the team in which you installed the app, and open a board. 5. Once you open the board, the modal should appear within a few seconds. From 10d047a329f55d4fafda3b1e40b9d98a1c1bed22 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Fri, 23 Feb 2024 07:50:54 +0100 Subject: [PATCH 10/15] update app.js to fix lint errors --- examples/terms-modal-banner-dyanmo/.gitignore | 146 +++++++ examples/terms-modal-banner-dyanmo/LICENSE | 21 ++ examples/terms-modal-banner-dyanmo/README.md | 114 ++++++ .../terms-modal-banner-dyanmo/readApp/app.js | 99 +++++ .../readApp/package.json | 15 + .../terms-modal-banner-dyanmo/template.yaml | 356 ++++++++++++++++++ .../webassets/app.html | 128 +++++++ .../webassets/modal.html | 192 ++++++++++ .../webassets/variables.js | 13 + .../terms-modal-banner-dyanmo/writeApp/app.js | 70 ++++ .../writeApp/package.json | 15 + 11 files changed, 1169 insertions(+) create mode 100644 examples/terms-modal-banner-dyanmo/.gitignore create mode 100644 examples/terms-modal-banner-dyanmo/LICENSE create mode 100644 examples/terms-modal-banner-dyanmo/README.md create mode 100644 examples/terms-modal-banner-dyanmo/readApp/app.js create mode 100644 examples/terms-modal-banner-dyanmo/readApp/package.json create mode 100644 examples/terms-modal-banner-dyanmo/template.yaml create mode 100644 examples/terms-modal-banner-dyanmo/webassets/app.html create mode 100644 examples/terms-modal-banner-dyanmo/webassets/modal.html create mode 100644 examples/terms-modal-banner-dyanmo/webassets/variables.js create mode 100644 examples/terms-modal-banner-dyanmo/writeApp/app.js create mode 100644 examples/terms-modal-banner-dyanmo/writeApp/package.json diff --git a/examples/terms-modal-banner-dyanmo/.gitignore b/examples/terms-modal-banner-dyanmo/.gitignore new file mode 100644 index 000000000..d9b5e2934 --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/.gitignore @@ -0,0 +1,146 @@ + +# Created by https://www.gitignore.io/api/osx,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +# End of https://www.gitignore.io/api/osx,node,linux,windows + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +#AWS/SAM +.aws-sam +packaged.yaml +samconfig.toml + +#jbesw-specific +testData/ diff --git a/examples/terms-modal-banner-dyanmo/LICENSE b/examples/terms-modal-banner-dyanmo/LICENSE new file mode 100644 index 000000000..caab4f9ff --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Miro + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/examples/terms-modal-banner-dyanmo/README.md b/examples/terms-modal-banner-dyanmo/README.md new file mode 100644 index 000000000..433fb5a76 --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/README.md @@ -0,0 +1,114 @@ +# Miro Terms Modal Banner App (Web-SDK V2 & AWS DynamoDB) + +This app creates a custom modal banner on your Miro boards that you can show to your users/attendees with any desired content and/or call to actions. It is typically used to accept terms and agreements before using a Miro board. + + To understand how to set up the app (including AWS resources needed to run the app) see the +[developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb) on Miro's Developer documentation. + +💸 **Important**: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. 💸 + +# 👨🏻‍💻 App Demo + +https://github.com/miroapp/app-examples/assets/10428517/7c97412a-b3ac-4811-965b-af992e7ff7f9 + +# 📒 Table of Contents + +- [Support](#support) +- [Included Features](#features) +- [Tools and Technologies](#tools) +- [Prerequisites](#prerequisites) +- [Associated Developer Tutorial](#tutorial) +- [Run the app locally](#run) +- [Folder Structure](#folder) +- [Contributing](#contributing) +- [License](#license) + +# 🙋🏻 Support + +If you have any questions or need assistance setting up this application, please reach out to your Miro Customer Success Manager or dedicated Miro Solutions Engineer. + +# ⚙️ Included Features + +- [Miro Web SDK](https://developers.miro.com/docs/web-sdk-reference) + - [miro.board.ui.canOpenModal()](https://developers.miro.com/docs/websdk-reference-ui#canopenmodal) + - [miro.board.ui.openModal()](https://developers.miro.com/docs/websdk-reference-ui#openmodal) + - [miro.board.ui.closeModal()](https://developers.miro.com/docs/websdk-reference-ui#closemodal) + - [miro.board.getUserInfo()](https://developers.miro.com/docs/websdk-reference-board#getuserinfo) + +# 🛠️ Tools and Technologies + +- [AWS CLI](https://aws.amazon.com/cli/) +- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) +- [AWS CloudFormation](https://aws.amazon.com/cloudformation/) +- [AWS DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) +- [AWS Lambda](https://aws.amazon.com/lambda/) +- [AWS API Gateway](https://aws.amazon.com/api-gateway/) + +# ✅ Prerequisites + +- You have a [Miro account](https://miro.com/signup/). +- You're [signed in to Miro](https://miro.com/login/). +- Your Miro account has a [Developer team](https://developers.miro.com/docs/create-a-developer-team). +- [NodeJS 16.x installed](https://nodejs.org/en/download/) +- [AWS CLI](https://aws.amazon.com/cli/) already configured with Administrator permission +- [AWS SAM CLI installed](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - minimum version 0.48. + +# 📖 Associated Developer Tutorial + +Using AWS S3 you can host your html files and serve them as regular web pages so they can load within Miro. In addition, you can also use AWS DynamoDB to add custom functionality to your Miro app to track which users have already accepted the modal, so that the modal does not re-appear again for those users. In this guide we will guide you on how to achieve this functionality using Miro and AWS DynamoDB. + +> See the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb) on Miro's Developer documentation. + +# 🏃🏽‍♂️ Run the app using AWS S3 + +Once you have finished all of the steps related to AWS in the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb), you can then create the Miro app. + +1. In your new Miro app settings, add in the `App URL`. It should end with `webassets/app.html`. +2. Open the [app manifest editor](https://developers.miro.com/docs/manually-create-an-app#step-2-configure-your-app-in-miro) by clicking **Edit in Manifest**. \ + In the app manifest editor, configure the app as follows ⚠️ Note: you will need to change your sdkUri to be your app.html which is hosted in the `webassets` folder of your S3 bucket. Mine is just shown as an example and then click save: + +```yaml +# See https://developers.miro.com/docs/app-manifest on how to use this +appName: s3-modal-banner +sdkVersion: SDK_V2 +sdkUri: >- + https://s3-miro-terms-banner-12345.s3.amazonaws.com/webassets/app.html +scopes: + - identity:read +``` + +3. Go back to your app home page, and under the `Permissions` section, you will see a blue button that says `Install app and get OAuth token`. Click that button. Then click on `Add` as shown in the video below. In the video we install a different app, but the process is the same regardless of the app. + +> ⚠️ We recommend to install your app on a [developer team](https://developers.miro.com/docs/create-a-developer-team) while you are developing or testing apps.⚠️ + +https://github.com/miroapp/app-examples/assets/10428517/588688ed-eb14-4b64-9dbb-66d1c07eea54 + +4. Go to the team in which you installed the app, and open a board. +5. Once you open the board, the modal should appear within a few seconds. +6. If you click accept, you should see a checkmark and then you should not see the modal again when refreshing the page or opening a new board + on that team. +7. You can also check your AWS DynamoDB database under `Explore Items` tab on the left side and then make sure you select your database which you created as part of this guide and then you should see some Items returned which should be the Miro UserID of the user which has clicked on the "accept" button on the terms. + +🎉 That's it. Great job! 🎉 + +# 🗂️ Folder structure + +``` +. +├── readApp +│ └── app.js // Source code for the serverless backend ("Read" database Lambda function) +├── webassets // HTML and JavaScript files for the Miro app. +│ ├── app.html // The code which uses Miro WebSDK to open the modal for the user. +│ └── modal.html // The code which serves as the UI for the terms which the user will accept. +├── writeApp +│ └── app.js // Source code for the serverless backend ("Write" database Lambda function) +├── template.yaml <-- The yaml code used to generate AWS resources via AWS SAM. +``` + +# 🫱🏻‍🫲🏽 Contributing + +If you want to contribute to this example, or any other Miro Open Source project, please review [Miro's contributing guide](https://github.com/miroapp/app-examples/blob/main/CONTRIBUTING.md). + +# 🪪 License + +[MIT License](https://github.com/miroapp/app-examples/blob/main/LICENSE). diff --git a/examples/terms-modal-banner-dyanmo/readApp/app.js b/examples/terms-modal-banner-dyanmo/readApp/app.js new file mode 100644 index 000000000..9600a32c0 --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/readApp/app.js @@ -0,0 +1,99 @@ +const AWS = require("aws-sdk"); + +exports.handler = async (event) => { + const dynamoDB = new AWS.DynamoDB.DocumentClient(); + const tableName = process.env.TABLE_NAME; + + const onlyLettersAndNumbers = function (str) { + return /^[A-Za-z0-9]*$/.test(str); + }; + + const responseHeaders = { + "Access-Control-Allow-Headers": "Content-Type,Accept,Cache-Control,Pragma", + "Access-Control-Allow-Origin": "*", // Replace wildcard (*) with your S3 bucket base URL (visible in your AWS SAML CLI Outputs) - See step 2.10 of the PDF guide https://drive.google.com/file/d/13fdsfiTGCBRWSmAv_7BuMBsWfg4_OWlO/view?usp=sharing + "Access-Control-Allow-Methods": "OPTIONS,GET", // Allow only GET request + "Content-Type": "application/json", + }; + + if ( + event && + !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && + !event.queryStringParameters + ) { + /* Returning a 400 error if the URL parameter "u" is not passed in the GET request */ + return { + statusCode: 400, + headers: responseHeaders, + body: JSON.stringify({ error: "Bad Request" }), + }; + } + + if ( + event && + !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && + !!Object.getOwnPropertyDescriptor(event.queryStringParameters, "u") && + event.queryStringParameters.u !== "" + ) { + const userId = event.queryStringParameters.u.toString(); + const isValidUserId = onlyLettersAndNumbers(userId); + + if (!isValidUserId) { + /* Returning a 409 error if the value of the URL parameter "u" passed in the GET request contains characters other than letters and numbers */ + return { + statusCode: 409, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Data" }), + }; + } + } else { + return { + statusCode: 415, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Request" }), + }; + } + + const userId = event.queryStringParameters.u.toString(); + + const params = { + TableName: tableName, + Key: { + id: userId, + }, + }; + + try { + const data = await dynamoDB.get(params).promise(); + + if ( + data && + !!Object.getOwnPropertyDescriptor(data, "Item") && + !!Object.getOwnPropertyDescriptor(data.Item, "id") && + data.Item.id.toString() === userId + ) { + /* Returning a 200 OK if the value of the URL parameter "u" matches an entry in the MiroBannerTermsAccepters DynamoDB table */ + return { + statusCode: 200, + //body: JSON.stringify(data.Item) + headers: responseHeaders, + body: JSON.stringify({ result: "success" }), + }; + } else { + /* Returning a 404 error if the value of the URL parameter "u" does not match any entry in the DynamoDB table */ + return { + statusCode: 404, + headers: responseHeaders, + body: JSON.stringify({ error: "Not Found" }), + }; + } + } catch (error) { + console.error("Error querying DynamoDB:", error); + + /* Returning a 500 error for any other error not catched above */ + return { + statusCode: 500, + headers: responseHeaders, + body: JSON.stringify({ error: "Internal Server Error" }), + }; + } +}; diff --git a/examples/terms-modal-banner-dyanmo/readApp/package.json b/examples/terms-modal-banner-dyanmo/readApp/package.json new file mode 100644 index 000000000..6479c9be9 --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/readApp/package.json @@ -0,0 +1,15 @@ +{ + "name": "MiroBannerTermsAcceptersReadApp", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Luis Colman, Miro Platform Architecture", + "license": "MIT-0", + "devDependencies": { + "aws-sdk": "^2.749.0" + } +} diff --git a/examples/terms-modal-banner-dyanmo/template.yaml b/examples/terms-modal-banner-dyanmo/template.yaml new file mode 100644 index 000000000..dbc44c7aa --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/template.yaml @@ -0,0 +1,356 @@ +AWSTemplateFormatVersion: "2010-09-09" +Transform: "AWS::Serverless-2016-10-31" +Description: Miro Banner Terms Accepters + +Resources: + ## S3 Bucket + MiroTermsBannerFrontend: + Type: AWS::S3::Bucket + Properties: + BucketName: + !Join [ + "", + [ + "s3-", + !Join [ + "-", + [ + "miro-terms-banner-frontend", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ], + ], + ] + CorsConfiguration: + CorsRules: + - AllowedHeaders: + - "*" + AllowedMethods: + - GET + AllowedOrigins: + - !Join [ + "", + [ + "https://s3-", + !Join [ + "-", + [ + "miro-terms-banner-frontend", + !Select [ + 4, + !Split [ + "-", + !Select [2, !Split ["/", !Ref AWS::StackId]], + ], + ], + ], + ], + ".s3.", + !Ref AWS::Region, + ".amazonaws.com", + ], + ] + PublicAccessBlockConfiguration: + BlockPublicAcls: false + BlockPublicPolicy: false + IgnorePublicAcls: false + RestrictPublicBuckets: false + + ## S3 Bucket Policy - This permission will make the contents of the S3 bucket publicly readable + ProductBucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Ref MiroTermsBannerFrontend + PolicyDocument: + Id: PublicReadPolicy + Version: "2012-10-17" + Statement: + - Sid: PublicReadForGetBucketObjects + Effect: Allow + Principal: "*" + Action: s3:GetObject + Resource: !Sub "arn:aws:s3:::${MiroTermsBannerFrontend}/*" + Condition: {} + + ## Database where users who have accepted the Miro Banner will be captured. + ## The "id" will be the numeric Miro User ID, stored as a string. You may use a hashed version of the Miro ID in this table instead (if desired) + MiroBannerTermsAcceptersTable: + Type: "AWS::Serverless::SimpleTable" + Properties: + TableName: + !Join [ + "-", + [ + "miro-terms-banner-accepters-database", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ] + PrimaryKey: + Name: id + Type: String + + ## IAM Role for the "Read" Lambda Function to query/read the database + MiroBannerTermsReadFunctionRole: + Type: "AWS::IAM::Role" + Properties: + RoleName: MiroBannerTermsReadFunctionRole + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: "sts:AssumeRole" + Policies: + - PolicyName: MiroBannerTermsDynamoDBReadPolicy + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - "dynamodb:GetItem" + Resource: !GetAtt MiroBannerTermsAcceptersTable.Arn + + ## IAM Role for the "Write" Lambda Function to write on the database + MiroBannerTermsWriteFunctionRole: + Type: "AWS::IAM::Role" + Properties: + RoleName: MiroBannerTermsWriteFunctionRole + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: "sts:AssumeRole" + Policies: + - PolicyName: MiroBannerTermsDynamoDBWritePolicy + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - "dynamodb:UpdateItem" + Resource: !GetAtt MiroBannerTermsAcceptersTable.Arn + + ## Lambda "Read" Function + MiroBannerTermsReadFunction: + Type: "AWS::Serverless::Function" + Properties: + FunctionName: + !Join [ + "-", + [ + "MiroBannerTermsReadFunction", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ] + Description: !Sub 'Lambda function for the "Miro Terms Modal app". It reads data from the DynamoDB table "${MiroBannerTermsAcceptersTable}"' + Handler: app.handler + Runtime: nodejs16.x + CodeUri: readApp/ + Timeout: 10 + Role: !GetAtt MiroBannerTermsReadFunctionRole.Arn + Environment: + Variables: + TABLE_NAME: !Ref MiroBannerTermsAcceptersTable + + ## Lambda "Write" Function + MiroBannerTermsWriteFunction: + Type: "AWS::Serverless::Function" + Properties: + FunctionName: + !Join [ + "-", + [ + "MiroBannerTermsWriteFunction", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ] + Description: !Sub 'Lambda function for the "Miro Terms Modal app". It writes data on the DynamoDB table "${MiroBannerTermsAcceptersTable}"' + Handler: app.handler + Runtime: nodejs16.x + CodeUri: writeApp/ + Timeout: 10 + Role: !GetAtt MiroBannerTermsWriteFunctionRole.Arn + Environment: + Variables: + TABLE_NAME: !Ref MiroBannerTermsAcceptersTable + + ## API Gateway + MiroBannerTermsAPI: + Type: "AWS::Serverless::Api" + Properties: + Name: + !Join [ + "", + [ + "api-", + !Join [ + "-", + [ + !Ref AWS::StackName, + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ], + ], + ] + Description: !Sub 'API endpoint for the "Miro Terms Modal app". It handles requests to read/write on the DynamoDB table "${MiroBannerTermsAcceptersTable}"' + StageName: Prod + DefinitionBody: + swagger: "2.0" + info: + title: "MiroBannerTermsAPI" + paths: + /w: + post: + x-amazon-apigateway-integration: + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MiroBannerTermsWriteFunction.Arn}/invocations + passthroughBehavior: "when_no_match" + httpMethod: POST + type: aws_proxy + responses: {} + security: + - sigv4: [] + options: + summary: CORS support + description: | + Enable CORS by returning correct headers + consumes: + - application/json + produces: + - application/json + tags: + - CORS + x-amazon-apigateway-integration: + type: mock + requestTemplates: + application/json: | + { + 'statusCode' : 200 + } + responses: + "default": + statusCode: "200" + responseParameters: + method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control,Pragma'" + method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'" + method.response.header.Access-Control-Allow-Origin: !Join + - "" + - - "'" + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - "'" + responseTemplates: + application/json: | + {} + responses: + "200": + description: Default response for CORS method + headers: + Access-Control-Allow-Headers: + type: "string" + Access-Control-Allow-Methods: + type: "string" + Access-Control-Allow-Origin: + type: "string" + /q: + get: + x-amazon-apigateway-integration: + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MiroBannerTermsReadFunction.Arn}/invocations + passthroughBehavior: "when_no_match" + httpMethod: POST + type: aws_proxy + responses: {} + security: + - sigv4: [] + options: + summary: CORS support + description: | + Enable CORS by returning correct headers + consumes: + - application/json + produces: + - application/json + tags: + - CORS + x-amazon-apigateway-integration: + type: mock + requestTemplates: + application/json: | + { + 'statusCode' : 200 + } + responses: + "default": + statusCode: "200" + responseParameters: + method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control,Pragma'" + method.response.header.Access-Control-Allow-Methods: "'OPTIONS,GET'" + method.response.header.Access-Control-Allow-Origin: !Join + - "" + - - "'" + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - "'" + responseTemplates: + application/json: | + {} + responses: + "200": + description: Default response for CORS method + headers: + Access-Control-Allow-Headers: + type: "string" + Access-Control-Allow-Methods: + type: "string" + Access-Control-Allow-Origin: + type: "string" + + ## "Read" Lambda Function Invoke Permission + MiroBannerTermsApiInvokePermissionRead: + Type: "AWS::Lambda::Permission" + Properties: + Action: "lambda:InvokeFunction" + FunctionName: !GetAtt MiroBannerTermsReadFunction.Arn + Principal: "apigateway.amazonaws.com" + SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MiroBannerTermsAPI}/*/*/*" + + ## "Write" Lambda Function Invoke Permission + MiroBannerTermsApiInvokePermissionWrite: + Type: "AWS::Lambda::Permission" + Properties: + Action: "lambda:InvokeFunction" + FunctionName: !GetAtt MiroBannerTermsWriteFunction.Arn + Principal: "apigateway.amazonaws.com" + SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MiroBannerTermsAPI}/*/*/*" + +## Take a note of the outputs for deploying the workflow templates in this sample application +Outputs: + S3BucketBaseUrl: + Description: "Base URL of the S3 bucket where the web assets of the Miro app will be hosted" + Value: !Sub "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + ApiBaseURL: + Description: "Base URL of HTTP API endpoint to read and write on the MiroBannerTermsAcceptersTable database" + Value: !Sub "https://${MiroBannerTermsAPI}.execute-api.${AWS::Region}.amazonaws.com" + DynamoDBTableName: + Description: "Name of the DynamoDB table that captures users who have accepted the terms banner in Miro" + Value: !Ref MiroBannerTermsAcceptersTable + S3BucketName: + Description: "Name of the S3 bucket where the web assets of the Miro app will be hosted (app.html, modal.html and variables.js)" + Value: !Ref MiroTermsBannerFrontend diff --git a/examples/terms-modal-banner-dyanmo/webassets/app.html b/examples/terms-modal-banner-dyanmo/webassets/app.html new file mode 100644 index 000000000..964ffd938 --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/webassets/app.html @@ -0,0 +1,128 @@ + + + + + + + + + + + + diff --git a/examples/terms-modal-banner-dyanmo/webassets/modal.html b/examples/terms-modal-banner-dyanmo/webassets/modal.html new file mode 100644 index 000000000..32028ba7d --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/webassets/modal.html @@ -0,0 +1,192 @@ + + + + + + + + + + +
+
+
+ +
+ To use Company Inc.'s Miro boards, please accept the + Usage Policy.
+ Please reach out to your IT administrator for more information on + the security requirements for using Company Inc.'s Miro boards. +
+
+ + + +
+
+
+
+ + + + diff --git a/examples/terms-modal-banner-dyanmo/webassets/variables.js b/examples/terms-modal-banner-dyanmo/webassets/variables.js new file mode 100644 index 000000000..8367f04cc --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/webassets/variables.js @@ -0,0 +1,13 @@ +/* variables.js */ +/* eslint-disable no-unused-vars */ + +var MODAL_URL = 'replace with your "modal.html" URL from AWS S3'; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com/webassets/modal.html';) + +var API_ENDPOINT_BASE_URL = + 'replace with the value of "ApiBaseURL" from your AWS SAM CLI Output'; // keep the single quotes around the value (e.g. 'https://e4g624kyue.execute-api.eu-central-1.amazonaws.com';) + +var SECONDS_TO_WAIT = 3; // Enter value as number (not string) - Enter value as number (not string) - This is the interval in seconds the app will check if the current user has accepted the terms modal. With the default value (3) the app will check every 3 seconds if the user has accepted the modal until the terms modal has been successfully accepted + +var MODAL_WITH = 590; // Enter value as number (not string) - Width of the modal pop-up in pixels - Adjust as desired + +var MODAL_HEIGHT = 300; // Enter value as number (not string) - Height of the modal pop-up in pixels - Adjusted as desired diff --git a/examples/terms-modal-banner-dyanmo/writeApp/app.js b/examples/terms-modal-banner-dyanmo/writeApp/app.js new file mode 100644 index 000000000..01835d981 --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/writeApp/app.js @@ -0,0 +1,70 @@ +/* Example of expected payload for the POST request: { "id": "Miro_User_ID" } */ + +const AWS = require("aws-sdk"); + +exports.handler = async (event) => { + const dynamoDB = new AWS.DynamoDB.DocumentClient(); + const tableName = process.env.TABLE_NAME; + const apiPayload = JSON.parse(event.body); + + const onlyLettersAndNumbers = function (str) { + return /^[A-Za-z0-9]*$/.test(str); + }; + + const responseHeaders = { + "Access-Control-Allow-Headers": "Content-Type,Accept,Cache-Control,Pragma", + "Access-Control-Allow-Origin": "*", // Replace wildcard (*) with your S3 bucket base URL (visible in your AWS SAML CLI Outputs) - See step 2.13 of the PDF guide https://drive.google.com/file/d/13fdsfiTGCBRWSmAv_7BuMBsWfg4_OWlO/view?usp=sharing + "Access-Control-Allow-Methods": "OPTIONS,POST", // Allow only POST request + "Content-Type": "application/json", + }; + + if (Object.getOwnPropertyDescriptor(apiPayload, "id")) { + const userId = apiPayload.id.toString(); + const isValidUserId = onlyLettersAndNumbers(userId); + + if (!isValidUserId || !userId) { + /* Returning a 409 error if the value of the "id" parameter posted contains characters other than a string with only letters and numbers */ + return { + statusCode: 409, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Data" }), + }; + } + + const params = { + TableName: tableName, + Key: { id: userId }, + UpdateExpression: "set hasAcceptedTerms = :hasAcceptedTerms", + ExpressionAttributeValues: { + ":hasAcceptedTerms": "yes", + }, + ReturnValues: "UPDATED_NEW", + }; + + try { + await dynamoDB.update(params).promise(); + return { + statusCode: 200, + //body: JSON.stringify(result.Attributes) + headers: responseHeaders, + body: JSON.stringify({ result: "success" }), + }; + } catch (error) { + console.error("Error updating item:", error); + + /* Returning a 500 error for any other errors */ + return { + statusCode: 500, + headers: responseHeaders, + body: JSON.stringify({ error: "Internal Server Error" }), + }; + } + } else { + /* Returning a 500 error if the "id" parameter was not passed in the posted payload */ + return { + statusCode: 415, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Request" }), + }; + } +}; diff --git a/examples/terms-modal-banner-dyanmo/writeApp/package.json b/examples/terms-modal-banner-dyanmo/writeApp/package.json new file mode 100644 index 000000000..77637e6da --- /dev/null +++ b/examples/terms-modal-banner-dyanmo/writeApp/package.json @@ -0,0 +1,15 @@ +{ + "name": "MiroBannerTermsAcceptersWriteApp", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Luis Colman, Miro Platform Architecture", + "license": "MIT-0", + "devDependencies": { + "aws-sdk": "^2.749.0" + } +} From 1479d4ded9da15ba2d0ae3e99805570652f98cf5 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Fri, 23 Feb 2024 08:37:19 +0100 Subject: [PATCH 11/15] removing s3 from this pr --- examples/terms-modal-banner-s3/.gitignore | 146 ------------- examples/terms-modal-banner-s3/README.md | 114 ---------- .../terms-modal-banner-s3/app-manifest.yaml | 8 - .../terms-modal-banner-s3/getSignedURL/app.js | 52 ----- .../getSignedURL/package.json | 15 -- examples/terms-modal-banner-s3/template.yaml | 186 ---------------- .../terms-modal-banner-s3/webassets/app.html | 127 ----------- .../webassets/modal.html | 199 ------------------ .../webassets/variables.js | 16 -- 9 files changed, 863 deletions(-) delete mode 100644 examples/terms-modal-banner-s3/.gitignore delete mode 100644 examples/terms-modal-banner-s3/README.md delete mode 100644 examples/terms-modal-banner-s3/app-manifest.yaml delete mode 100644 examples/terms-modal-banner-s3/getSignedURL/app.js delete mode 100644 examples/terms-modal-banner-s3/getSignedURL/package.json delete mode 100644 examples/terms-modal-banner-s3/template.yaml delete mode 100644 examples/terms-modal-banner-s3/webassets/app.html delete mode 100644 examples/terms-modal-banner-s3/webassets/modal.html delete mode 100644 examples/terms-modal-banner-s3/webassets/variables.js diff --git a/examples/terms-modal-banner-s3/.gitignore b/examples/terms-modal-banner-s3/.gitignore deleted file mode 100644 index d9b5e2934..000000000 --- a/examples/terms-modal-banner-s3/.gitignore +++ /dev/null @@ -1,146 +0,0 @@ - -# Created by https://www.gitignore.io/api/osx,node,linux,windows - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Typescript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - - -### OSX ### -*.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - - -# End of https://www.gitignore.io/api/osx,node,linux,windows - -# Editor directories and files -.idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? - -#AWS/SAM -.aws-sam -packaged.yaml -samconfig.toml - -#jbesw-specific -testData/ diff --git a/examples/terms-modal-banner-s3/README.md b/examples/terms-modal-banner-s3/README.md deleted file mode 100644 index 506542a60..000000000 --- a/examples/terms-modal-banner-s3/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# Miro Terms Modal Banner App (Web-SDK V2 & AWS S3) - -This app creates a custom modal banner on your Miro boards that you can show to your users/attendees with any desired content and/or call to actions. It is typically used to accept terms and agreements before using a Miro board. - - To understand how to set up the app (including AWS resources needed to run the app) see the -[developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-s3) on Miro's Developer documentation. - -💸 **Important**: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. 💸 - -# 👨🏻‍💻 App Demo - -https://github.com/miroapp/app-examples/assets/10428517/16e009f7-70f2-435b-bd61-f11845ad3197 - -# 📒 Table of Contents - -- [Support](#support) -- [Included Features](#features) -- [Tools and Technologies](#tools) -- [Prerequisites](#prerequisites) -- [Associated Developer Tutorial](#tutorial) -- [Run the app locally](#run) -- [Folder Structure](#folder) -- [Contributing](#contributing) -- [License](#license) - -# 🙋🏻 Support - -If you have any questions or need assistance setting up this application, please reach out to your Miro Customer Success Manager or dedicated Miro Solutions Engineer. - -# ⚙️ Included Features - -- [Miro Web SDK](https://developers.miro.com/docs/web-sdk-reference) - - [miro.board.ui.canOpenModal()](https://developers.miro.com/docs/websdk-reference-ui#canopenmodal) - - [miro.board.ui.openModal()](https://developers.miro.com/docs/websdk-reference-ui#openmodal) - - [miro.board.ui.closeModal()](https://developers.miro.com/docs/websdk-reference-ui#closemodal) - - [miro.board.getUserInfo()](https://developers.miro.com/docs/websdk-reference-board#getuserinfo) - -# 🛠️ Tools and Technologies - -- [AWS CLI](https://aws.amazon.com/cli/) -- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -- [AWS CloudFormation](https://aws.amazon.com/cloudformation/) -- [AWS S3](https://react.dev/) -- [AWS Lambda](https://react.dev/) -- [AWS API Gateway](https://aws.amazon.com/api-gateway/) - -# ✅ Prerequisites - -- You have a [Miro account](https://miro.com/signup/). -- You're [signed in to Miro](https://miro.com/login/). -- Your Miro account has a [Developer team](https://developers.miro.com/docs/create-a-developer-team). -- [NodeJS 16.x installed](https://nodejs.org/en/download/) -- [AWS CLI](https://aws.amazon.com/cli/) already configured with Administrator permission -- [AWS SAM CLI installed](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - minimum version 0.48. - -# 📖 Associated Developer Tutorial - -Using AWS S3 you can host your html files and serve them as regular web pages so they can load within Miro. In addition, you can also use AWS S3 to add custom functionality to your Miro app to track which users have already accepted the modal, so that the modal does not re-appear again for those users. In this guide we will guide you on how to achieve this functionality using Miro and AWS S3. - -> See the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-s3) on Miro's Developer documentation. - -# 🏃🏽‍♂️ Run the app using AWS S3 - -Once you have finished all of the steps related to AWS in the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-s3), you can then create the Miro app. - -1. In your new Miro app settings, add in the `App URL`. It should end with `webassets/app.html`. -2. Open the [app manifest editor](https://developers.miro.com/docs/manually-create-an-app#step-2-configure-your-app-in-miro) by clicking **Edit in Manifest**. \ - In the app manifest editor, configure the app as follows ⚠️ Note: you will need to change your sdkUri to be your app.html which is hosted in the `webassets` folder of your S3 bucket. Mine is just shown as an example and then click save: - -```yaml -# See https://developers.miro.com/docs/app-manifest on how to use this -appName: s3-modal-banner -sdkVersion: SDK_V2 -sdkUri: >- - https://s3-miro-terms-banner-12345.s3.amazonaws.com/webassets/app.html -scopes: - - identity:read -``` - -3. Go back to your app home page, and under the `Permissions` section, you will see a blue button that says `Install app and get OAuth token`. Click that button. Then click on `Add` as shown in the video below. In the video we install a different app, but the process is the same regardless of the app. - -> ⚠️ We recommend to install your app on a [developer team](https://developers.miro.com/docs/create-a-developer-team) while you are developing or testing apps.⚠️ - -https://github.com/miroapp/app-examples/assets/10428517/43922ea1-d619-4480-af23-029a1a4e67d8 - -4. Go to the team in which you installed the app, and open a board. -5. Once you open the board, the modal should appear within a few seconds. -6. If you click accept, you should see a checkmark and then you should not see the modal again when refreshing the page or opening a new board - on that team. -7. You can also check your AWS S3 bucket and see that a new folder `users` has been added. The userID of the user which clicked on `accept` will - be added to the `users` folder in AWS S3. - -🎉 That's it. Great job! 🎉 - -# 🗂️ Folder structure - -``` -. -├── getSignedURL <-- Source code for the serverless backend. -│ └── app.js // The code to add userID to S3 bucket once user accepts terms. -├── webassets <-- HTML and JavaScript files for the Miro app. -│ ├── app.html // The code which uses Miro WebSDK to open the modal for the user. -│ └── modal.html // The code which serves as the UI for the terms which the user will accept. - -├── template.yaml <-- The yaml code used to generate AWS resources via AWS SAM. -``` - -# 🫱🏻‍🫲🏽 Contributing - -If you want to contribute to this example, or any other Miro Open Source project, please review [Miro's contributing guide](https://github.com/miroapp/app-examples/blob/main/CONTRIBUTING.md). - -# 🪪 License - -[MIT License](https://github.com/miroapp/app-examples/blob/main/LICENSE). diff --git a/examples/terms-modal-banner-s3/app-manifest.yaml b/examples/terms-modal-banner-s3/app-manifest.yaml deleted file mode 100644 index 5fbf52eb0..000000000 --- a/examples/terms-modal-banner-s3/app-manifest.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# See https://developers.miro.com/docs/app-manifest on how to use this -# make sure to replace the sdkUri with the correct URL (it will be different for each deployment) -appName: s3-modal-banner -sdkVersion: SDK_V2 -sdkUri: >- - https://s3-miro-terms-banner-12345.s3.amazonaws.com/webassets/app.html -scopes: - - identity:read diff --git a/examples/terms-modal-banner-s3/getSignedURL/app.js b/examples/terms-modal-banner-s3/getSignedURL/app.js deleted file mode 100644 index 4548993c5..000000000 --- a/examples/terms-modal-banner-s3/getSignedURL/app.js +++ /dev/null @@ -1,52 +0,0 @@ -/* - Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. - Permission is hereby granted, free of charge, to any person obtaining a copy of this - software and associated documentation files (the "Software"), to deal in the Software - without restriction, including without limitation the rights to use, copy, modify, - merge, publish, distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A - PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -"use strict"; - -const AWS = require("aws-sdk"); -AWS.config.update({ region: process.env.AWS_REGION }); -const s3 = new AWS.S3({ - apiVersion: "2006-03-01", - signatureVersion: "v4", -}); - -// Change this value to adjust the signed URL's expiration -const URL_EXPIRATION_SECONDS = 300; - -// Main Lambda entry point -exports.handler = async (event) => { - return await getUploadURL(event); -}; - -const getUploadURL = async function (event) { - const userID = event.queryStringParameters.id; - const Key = userID; - - // Get signed URL from S3 - const s3Params = { - Bucket: process.env.MiroBannerAccepters + "/users", - Key, - Expires: URL_EXPIRATION_SECONDS, - ContentType: "text/plain", - }; - - console.log("Params: ", s3Params); - const uploadURL = await s3.getSignedUrlPromise("putObject", s3Params); - - return JSON.stringify({ - uploadURL: uploadURL, - Key, - }); -}; diff --git a/examples/terms-modal-banner-s3/getSignedURL/package.json b/examples/terms-modal-banner-s3/getSignedURL/package.json deleted file mode 100644 index 83453a499..000000000 --- a/examples/terms-modal-banner-s3/getSignedURL/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "miro-terms-banner-s3-uploader", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "James Beswick, AWS Serverless", - "license": "MIT-0", - "devDependencies": { - "aws-sdk": "^2.749.0" - } -} diff --git a/examples/terms-modal-banner-s3/template.yaml b/examples/terms-modal-banner-s3/template.yaml deleted file mode 100644 index 7fafdc5ec..000000000 --- a/examples/terms-modal-banner-s3/template.yaml +++ /dev/null @@ -1,186 +0,0 @@ -AWSTemplateFormatVersion: 2010-09-09 -Transform: AWS::Serverless-2016-10-31 -Description: S3 Miro Banner Accepters - -Resources: - ## S3 bucket - S3MiroBannerAccepters: - Type: AWS::S3::Bucket - Properties: - BucketName: - !Join [ - "", - [ - "s3-", - !Join [ - "-", - [ - !Ref AWS::StackName, - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ], - ], - ] - CorsConfiguration: - CorsRules: - - AllowedHeaders: - - "*" - AllowedMethods: - - GET - - PUT - - HEAD - AllowedOrigins: - - !Join [ - "", - [ - "https://s3-", - !Join [ - "-", - [ - !Ref AWS::StackName, - !Select [ - 4, - !Split [ - "-", - !Select [2, !Split ["/", !Ref AWS::StackId]], - ], - ], - ], - ], - ".s3.", - !Ref AWS::Region, - ".amazonaws.com", - ], - ] - - !Join [ - "", - [ - "https://s3-", - !Join [ - "-", - [ - !Ref AWS::StackName, - !Select [ - 4, - !Split [ - "-", - !Select [2, !Split ["/", !Ref AWS::StackId]], - ], - ], - ], - ], - ".s3.amazonaws.com", - ], - ] - PublicAccessBlockConfiguration: - BlockPublicAcls: false - BlockPublicPolicy: false - IgnorePublicAcls: false - RestrictPublicBuckets: false - - ## This permission will make the contents of the S3 bucket publicly readable - ProductBucketPolicy: - Type: AWS::S3::BucketPolicy - Properties: - Bucket: !Ref S3MiroBannerAccepters - PolicyDocument: - Id: PublicReadPolicy - Version: "2012-10-17" - Statement: - - Sid: PublicReadForGetBucketObjects - Effect: Allow - Principal: "*" - Action: s3:GetObject - Resource: !Sub "arn:aws:s3:::${S3MiroBannerAccepters}/*" - - # HTTP API - MiroBannerAPI: - Type: AWS::Serverless::HttpApi - Properties: - Name: - !Join [ - "", - [ - "api-", - !Join [ - "-", - [ - !Ref AWS::StackName, - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ], - ], - ] - Description: !Sub 'API endpoint for the "Miro Terms Modal app". It handles requests to write on the S3 bucket "${S3MiroBannerAccepters}/users"' - # CORS configuration - The s3 bucket origin will be added as the only allowed origin. - # See https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-httpapi-httpapicorsconfiguration.html - CorsConfiguration: - AllowMethods: - - GET - - OPTIONS - AllowHeaders: - - "*" - AllowOrigins: - - !Sub "https://${S3MiroBannerAccepters}.s3.${AWS::Region}.amazonaws.com" - - !Sub "https://${S3MiroBannerAccepters}.s3.amazonaws.com" - - ## Lambda function - MiroBannerAcceptersRequestFunction: - # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction - Type: AWS::Serverless::Function - Properties: - FunctionName: - !Join [ - "-", - [ - !Ref AWS::StackName, - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ] - Description: !Sub 'Lambda function for the "Miro Terms Modal app". It writes data on the S3 bucket "${S3MiroBannerAccepters}/users"' - CodeUri: getSignedURL/ - Handler: app.handler - Runtime: nodejs16.x - Timeout: 3 - MemorySize: 128 - Environment: - Variables: - MiroBannerAccepters: !Ref S3MiroBannerAccepters - Policies: - - S3WritePolicy: - BucketName: !Ref S3MiroBannerAccepters - ## This permission allows the Lambda function to request signed URLs - ## for objects that will be publicly readable. Uncomment if you want this ACL. - - Statement: - - Effect: Allow - Resource: !Sub "arn:aws:s3:::${S3MiroBannerAccepters}/" - Action: - - s3:putObjectAcl - Events: - UploadAssetAPI: - Type: HttpApi - Properties: - Path: /uploads - Method: get - ApiId: !Ref MiroBannerAPI - -## Take a note of the outputs for deploying the workflow templates in this sample application -Outputs: - S3RecordTermsAcceptanceEndpointUrl: - Description: "HTTP API endpoint URL to get the S3 signed URL to write on the S3 bucket" - Value: !Sub "https://${MiroBannerAPI}.execute-api.${AWS::Region}.amazonaws.com" - S3BucketName: - Description: "Name of the S3 bucket that captures users who have accepted the terms modal in Miro" - Value: !Ref S3MiroBannerAccepters - S3BucketBaseUrl: - Description: "Base URL of the S3 bucket - it will be used to query/read users who have already accepted the terms modal" - Value: !Sub "https://${S3MiroBannerAccepters}.s3.${AWS::Region}.amazonaws.com" diff --git a/examples/terms-modal-banner-s3/webassets/app.html b/examples/terms-modal-banner-s3/webassets/app.html deleted file mode 100644 index 603fce7a9..000000000 --- a/examples/terms-modal-banner-s3/webassets/app.html +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - - - diff --git a/examples/terms-modal-banner-s3/webassets/modal.html b/examples/terms-modal-banner-s3/webassets/modal.html deleted file mode 100644 index 3dbd60089..000000000 --- a/examples/terms-modal-banner-s3/webassets/modal.html +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - - -
-
-
- -
- To use Company Inc.'s Miro boards, please accept the - Usage Policy.
- Please reach out to your IT administrator for more information on - the security requirements for using Company Inc.'s Miro boards. -
-
- - - -
-
-
-
- - - - diff --git a/examples/terms-modal-banner-s3/webassets/variables.js b/examples/terms-modal-banner-s3/webassets/variables.js deleted file mode 100644 index a0563f0be..000000000 --- a/examples/terms-modal-banner-s3/webassets/variables.js +++ /dev/null @@ -1,16 +0,0 @@ -/* variables.js */ -/* eslint-disable no-unused-vars */ - -var MODAL_URL = 'replace with your "modal.html" URL from AWS S3'; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com/webassets/modal.html';) - -var S3_RECORD_TERMS_ACCEPTANCE_ENDPOINT_URL = - 'replace with the value of "S3RecordTermsAcceptanceEndpointUrl" from your AWS SAM CLI Output'; // keep the single quotes around the value (e.g. 'https://e4g624kyue.execute-api.eu-central-1.amazonaws.com';) - -var S3_BUCKET_BASE_URL = - 'replace with the value of "S3BucketBaseUrl" from your AWS SAM CLI Output'; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com';) - -var SECONDS_TO_WAIT = 3; // Enter value as number (not string) - Enter value as number (not string) - This is the interval in seconds the app will check if the current user has accepted the terms modal. With the default value (3) the app will check every 3 seconds if the user has accepted the modal until the terms modal has been successfully accepted - -var MODAL_WITH = 590; // Enter value as number (not string) - Width of the modal pop-up in pixels - Adjust as desired - -var MODAL_HEIGHT = 300; // Enter value as number (not string) - Height of the modal pop-up in pixels - Adjusted as desired From 65934943474f03027cc700fdb13cf058b20cc121 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Fri, 23 Feb 2024 11:13:56 +0100 Subject: [PATCH 12/15] add s3 --- examples/terms-modal-banner-dyanmo/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/terms-modal-banner-dyanmo/README.md b/examples/terms-modal-banner-dyanmo/README.md index 433fb5a76..c74d3ea6f 100644 --- a/examples/terms-modal-banner-dyanmo/README.md +++ b/examples/terms-modal-banner-dyanmo/README.md @@ -41,6 +41,7 @@ If you have any questions or need assistance setting up this application, please - [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - [AWS CloudFormation](https://aws.amazon.com/cloudformation/) - [AWS DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) +- [AWS S3](https://docs.aws.amazon.com/s3) - [AWS Lambda](https://aws.amazon.com/lambda/) - [AWS API Gateway](https://aws.amazon.com/api-gateway/) From 0b647cb50666ffbc9389b945f671a0cc546e51ed Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Mon, 26 Feb 2024 10:52:31 +0100 Subject: [PATCH 13/15] fix typo in directory name --- .../terms-modal-banner-dynamodb/.gitignore | 146 +++++++ examples/terms-modal-banner-dynamodb/LICENSE | 21 ++ .../terms-modal-banner-dynamodb/README.md | 115 ++++++ .../readApp/app.js | 99 +++++ .../readApp/package.json | 15 + .../terms-modal-banner-dynamodb/template.yaml | 356 ++++++++++++++++++ .../webassets/app.html | 128 +++++++ .../webassets/modal.html | 192 ++++++++++ .../webassets/variables.js | 13 + .../writeApp/app.js | 70 ++++ .../writeApp/package.json | 15 + 11 files changed, 1170 insertions(+) create mode 100644 examples/terms-modal-banner-dynamodb/.gitignore create mode 100644 examples/terms-modal-banner-dynamodb/LICENSE create mode 100644 examples/terms-modal-banner-dynamodb/README.md create mode 100644 examples/terms-modal-banner-dynamodb/readApp/app.js create mode 100644 examples/terms-modal-banner-dynamodb/readApp/package.json create mode 100644 examples/terms-modal-banner-dynamodb/template.yaml create mode 100644 examples/terms-modal-banner-dynamodb/webassets/app.html create mode 100644 examples/terms-modal-banner-dynamodb/webassets/modal.html create mode 100644 examples/terms-modal-banner-dynamodb/webassets/variables.js create mode 100644 examples/terms-modal-banner-dynamodb/writeApp/app.js create mode 100644 examples/terms-modal-banner-dynamodb/writeApp/package.json diff --git a/examples/terms-modal-banner-dynamodb/.gitignore b/examples/terms-modal-banner-dynamodb/.gitignore new file mode 100644 index 000000000..d9b5e2934 --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/.gitignore @@ -0,0 +1,146 @@ + +# Created by https://www.gitignore.io/api/osx,node,linux,windows + +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Typescript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + + +### OSX ### +*.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msm +*.msp + +# Windows shortcuts +*.lnk + + +# End of https://www.gitignore.io/api/osx,node,linux,windows + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? + +#AWS/SAM +.aws-sam +packaged.yaml +samconfig.toml + +#jbesw-specific +testData/ diff --git a/examples/terms-modal-banner-dynamodb/LICENSE b/examples/terms-modal-banner-dynamodb/LICENSE new file mode 100644 index 000000000..caab4f9ff --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Miro + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/examples/terms-modal-banner-dynamodb/README.md b/examples/terms-modal-banner-dynamodb/README.md new file mode 100644 index 000000000..c74d3ea6f --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/README.md @@ -0,0 +1,115 @@ +# Miro Terms Modal Banner App (Web-SDK V2 & AWS DynamoDB) + +This app creates a custom modal banner on your Miro boards that you can show to your users/attendees with any desired content and/or call to actions. It is typically used to accept terms and agreements before using a Miro board. + + To understand how to set up the app (including AWS resources needed to run the app) see the +[developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb) on Miro's Developer documentation. + +💸 **Important**: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. 💸 + +# 👨🏻‍💻 App Demo + +https://github.com/miroapp/app-examples/assets/10428517/7c97412a-b3ac-4811-965b-af992e7ff7f9 + +# 📒 Table of Contents + +- [Support](#support) +- [Included Features](#features) +- [Tools and Technologies](#tools) +- [Prerequisites](#prerequisites) +- [Associated Developer Tutorial](#tutorial) +- [Run the app locally](#run) +- [Folder Structure](#folder) +- [Contributing](#contributing) +- [License](#license) + +# 🙋🏻 Support + +If you have any questions or need assistance setting up this application, please reach out to your Miro Customer Success Manager or dedicated Miro Solutions Engineer. + +# ⚙️ Included Features + +- [Miro Web SDK](https://developers.miro.com/docs/web-sdk-reference) + - [miro.board.ui.canOpenModal()](https://developers.miro.com/docs/websdk-reference-ui#canopenmodal) + - [miro.board.ui.openModal()](https://developers.miro.com/docs/websdk-reference-ui#openmodal) + - [miro.board.ui.closeModal()](https://developers.miro.com/docs/websdk-reference-ui#closemodal) + - [miro.board.getUserInfo()](https://developers.miro.com/docs/websdk-reference-board#getuserinfo) + +# 🛠️ Tools and Technologies + +- [AWS CLI](https://aws.amazon.com/cli/) +- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) +- [AWS CloudFormation](https://aws.amazon.com/cloudformation/) +- [AWS DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) +- [AWS S3](https://docs.aws.amazon.com/s3) +- [AWS Lambda](https://aws.amazon.com/lambda/) +- [AWS API Gateway](https://aws.amazon.com/api-gateway/) + +# ✅ Prerequisites + +- You have a [Miro account](https://miro.com/signup/). +- You're [signed in to Miro](https://miro.com/login/). +- Your Miro account has a [Developer team](https://developers.miro.com/docs/create-a-developer-team). +- [NodeJS 16.x installed](https://nodejs.org/en/download/) +- [AWS CLI](https://aws.amazon.com/cli/) already configured with Administrator permission +- [AWS SAM CLI installed](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - minimum version 0.48. + +# 📖 Associated Developer Tutorial + +Using AWS S3 you can host your html files and serve them as regular web pages so they can load within Miro. In addition, you can also use AWS DynamoDB to add custom functionality to your Miro app to track which users have already accepted the modal, so that the modal does not re-appear again for those users. In this guide we will guide you on how to achieve this functionality using Miro and AWS DynamoDB. + +> See the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb) on Miro's Developer documentation. + +# 🏃🏽‍♂️ Run the app using AWS S3 + +Once you have finished all of the steps related to AWS in the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb), you can then create the Miro app. + +1. In your new Miro app settings, add in the `App URL`. It should end with `webassets/app.html`. +2. Open the [app manifest editor](https://developers.miro.com/docs/manually-create-an-app#step-2-configure-your-app-in-miro) by clicking **Edit in Manifest**. \ + In the app manifest editor, configure the app as follows ⚠️ Note: you will need to change your sdkUri to be your app.html which is hosted in the `webassets` folder of your S3 bucket. Mine is just shown as an example and then click save: + +```yaml +# See https://developers.miro.com/docs/app-manifest on how to use this +appName: s3-modal-banner +sdkVersion: SDK_V2 +sdkUri: >- + https://s3-miro-terms-banner-12345.s3.amazonaws.com/webassets/app.html +scopes: + - identity:read +``` + +3. Go back to your app home page, and under the `Permissions` section, you will see a blue button that says `Install app and get OAuth token`. Click that button. Then click on `Add` as shown in the video below. In the video we install a different app, but the process is the same regardless of the app. + +> ⚠️ We recommend to install your app on a [developer team](https://developers.miro.com/docs/create-a-developer-team) while you are developing or testing apps.⚠️ + +https://github.com/miroapp/app-examples/assets/10428517/588688ed-eb14-4b64-9dbb-66d1c07eea54 + +4. Go to the team in which you installed the app, and open a board. +5. Once you open the board, the modal should appear within a few seconds. +6. If you click accept, you should see a checkmark and then you should not see the modal again when refreshing the page or opening a new board + on that team. +7. You can also check your AWS DynamoDB database under `Explore Items` tab on the left side and then make sure you select your database which you created as part of this guide and then you should see some Items returned which should be the Miro UserID of the user which has clicked on the "accept" button on the terms. + +🎉 That's it. Great job! 🎉 + +# 🗂️ Folder structure + +``` +. +├── readApp +│ └── app.js // Source code for the serverless backend ("Read" database Lambda function) +├── webassets // HTML and JavaScript files for the Miro app. +│ ├── app.html // The code which uses Miro WebSDK to open the modal for the user. +│ └── modal.html // The code which serves as the UI for the terms which the user will accept. +├── writeApp +│ └── app.js // Source code for the serverless backend ("Write" database Lambda function) +├── template.yaml <-- The yaml code used to generate AWS resources via AWS SAM. +``` + +# 🫱🏻‍🫲🏽 Contributing + +If you want to contribute to this example, or any other Miro Open Source project, please review [Miro's contributing guide](https://github.com/miroapp/app-examples/blob/main/CONTRIBUTING.md). + +# 🪪 License + +[MIT License](https://github.com/miroapp/app-examples/blob/main/LICENSE). diff --git a/examples/terms-modal-banner-dynamodb/readApp/app.js b/examples/terms-modal-banner-dynamodb/readApp/app.js new file mode 100644 index 000000000..9600a32c0 --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/readApp/app.js @@ -0,0 +1,99 @@ +const AWS = require("aws-sdk"); + +exports.handler = async (event) => { + const dynamoDB = new AWS.DynamoDB.DocumentClient(); + const tableName = process.env.TABLE_NAME; + + const onlyLettersAndNumbers = function (str) { + return /^[A-Za-z0-9]*$/.test(str); + }; + + const responseHeaders = { + "Access-Control-Allow-Headers": "Content-Type,Accept,Cache-Control,Pragma", + "Access-Control-Allow-Origin": "*", // Replace wildcard (*) with your S3 bucket base URL (visible in your AWS SAML CLI Outputs) - See step 2.10 of the PDF guide https://drive.google.com/file/d/13fdsfiTGCBRWSmAv_7BuMBsWfg4_OWlO/view?usp=sharing + "Access-Control-Allow-Methods": "OPTIONS,GET", // Allow only GET request + "Content-Type": "application/json", + }; + + if ( + event && + !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && + !event.queryStringParameters + ) { + /* Returning a 400 error if the URL parameter "u" is not passed in the GET request */ + return { + statusCode: 400, + headers: responseHeaders, + body: JSON.stringify({ error: "Bad Request" }), + }; + } + + if ( + event && + !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && + !!Object.getOwnPropertyDescriptor(event.queryStringParameters, "u") && + event.queryStringParameters.u !== "" + ) { + const userId = event.queryStringParameters.u.toString(); + const isValidUserId = onlyLettersAndNumbers(userId); + + if (!isValidUserId) { + /* Returning a 409 error if the value of the URL parameter "u" passed in the GET request contains characters other than letters and numbers */ + return { + statusCode: 409, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Data" }), + }; + } + } else { + return { + statusCode: 415, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Request" }), + }; + } + + const userId = event.queryStringParameters.u.toString(); + + const params = { + TableName: tableName, + Key: { + id: userId, + }, + }; + + try { + const data = await dynamoDB.get(params).promise(); + + if ( + data && + !!Object.getOwnPropertyDescriptor(data, "Item") && + !!Object.getOwnPropertyDescriptor(data.Item, "id") && + data.Item.id.toString() === userId + ) { + /* Returning a 200 OK if the value of the URL parameter "u" matches an entry in the MiroBannerTermsAccepters DynamoDB table */ + return { + statusCode: 200, + //body: JSON.stringify(data.Item) + headers: responseHeaders, + body: JSON.stringify({ result: "success" }), + }; + } else { + /* Returning a 404 error if the value of the URL parameter "u" does not match any entry in the DynamoDB table */ + return { + statusCode: 404, + headers: responseHeaders, + body: JSON.stringify({ error: "Not Found" }), + }; + } + } catch (error) { + console.error("Error querying DynamoDB:", error); + + /* Returning a 500 error for any other error not catched above */ + return { + statusCode: 500, + headers: responseHeaders, + body: JSON.stringify({ error: "Internal Server Error" }), + }; + } +}; diff --git a/examples/terms-modal-banner-dynamodb/readApp/package.json b/examples/terms-modal-banner-dynamodb/readApp/package.json new file mode 100644 index 000000000..6479c9be9 --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/readApp/package.json @@ -0,0 +1,15 @@ +{ + "name": "MiroBannerTermsAcceptersReadApp", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Luis Colman, Miro Platform Architecture", + "license": "MIT-0", + "devDependencies": { + "aws-sdk": "^2.749.0" + } +} diff --git a/examples/terms-modal-banner-dynamodb/template.yaml b/examples/terms-modal-banner-dynamodb/template.yaml new file mode 100644 index 000000000..dbc44c7aa --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/template.yaml @@ -0,0 +1,356 @@ +AWSTemplateFormatVersion: "2010-09-09" +Transform: "AWS::Serverless-2016-10-31" +Description: Miro Banner Terms Accepters + +Resources: + ## S3 Bucket + MiroTermsBannerFrontend: + Type: AWS::S3::Bucket + Properties: + BucketName: + !Join [ + "", + [ + "s3-", + !Join [ + "-", + [ + "miro-terms-banner-frontend", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ], + ], + ] + CorsConfiguration: + CorsRules: + - AllowedHeaders: + - "*" + AllowedMethods: + - GET + AllowedOrigins: + - !Join [ + "", + [ + "https://s3-", + !Join [ + "-", + [ + "miro-terms-banner-frontend", + !Select [ + 4, + !Split [ + "-", + !Select [2, !Split ["/", !Ref AWS::StackId]], + ], + ], + ], + ], + ".s3.", + !Ref AWS::Region, + ".amazonaws.com", + ], + ] + PublicAccessBlockConfiguration: + BlockPublicAcls: false + BlockPublicPolicy: false + IgnorePublicAcls: false + RestrictPublicBuckets: false + + ## S3 Bucket Policy - This permission will make the contents of the S3 bucket publicly readable + ProductBucketPolicy: + Type: AWS::S3::BucketPolicy + Properties: + Bucket: !Ref MiroTermsBannerFrontend + PolicyDocument: + Id: PublicReadPolicy + Version: "2012-10-17" + Statement: + - Sid: PublicReadForGetBucketObjects + Effect: Allow + Principal: "*" + Action: s3:GetObject + Resource: !Sub "arn:aws:s3:::${MiroTermsBannerFrontend}/*" + Condition: {} + + ## Database where users who have accepted the Miro Banner will be captured. + ## The "id" will be the numeric Miro User ID, stored as a string. You may use a hashed version of the Miro ID in this table instead (if desired) + MiroBannerTermsAcceptersTable: + Type: "AWS::Serverless::SimpleTable" + Properties: + TableName: + !Join [ + "-", + [ + "miro-terms-banner-accepters-database", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ] + PrimaryKey: + Name: id + Type: String + + ## IAM Role for the "Read" Lambda Function to query/read the database + MiroBannerTermsReadFunctionRole: + Type: "AWS::IAM::Role" + Properties: + RoleName: MiroBannerTermsReadFunctionRole + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: "sts:AssumeRole" + Policies: + - PolicyName: MiroBannerTermsDynamoDBReadPolicy + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - "dynamodb:GetItem" + Resource: !GetAtt MiroBannerTermsAcceptersTable.Arn + + ## IAM Role for the "Write" Lambda Function to write on the database + MiroBannerTermsWriteFunctionRole: + Type: "AWS::IAM::Role" + Properties: + RoleName: MiroBannerTermsWriteFunctionRole + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: "sts:AssumeRole" + Policies: + - PolicyName: MiroBannerTermsDynamoDBWritePolicy + PolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Action: + - "dynamodb:UpdateItem" + Resource: !GetAtt MiroBannerTermsAcceptersTable.Arn + + ## Lambda "Read" Function + MiroBannerTermsReadFunction: + Type: "AWS::Serverless::Function" + Properties: + FunctionName: + !Join [ + "-", + [ + "MiroBannerTermsReadFunction", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ] + Description: !Sub 'Lambda function for the "Miro Terms Modal app". It reads data from the DynamoDB table "${MiroBannerTermsAcceptersTable}"' + Handler: app.handler + Runtime: nodejs16.x + CodeUri: readApp/ + Timeout: 10 + Role: !GetAtt MiroBannerTermsReadFunctionRole.Arn + Environment: + Variables: + TABLE_NAME: !Ref MiroBannerTermsAcceptersTable + + ## Lambda "Write" Function + MiroBannerTermsWriteFunction: + Type: "AWS::Serverless::Function" + Properties: + FunctionName: + !Join [ + "-", + [ + "MiroBannerTermsWriteFunction", + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ] + Description: !Sub 'Lambda function for the "Miro Terms Modal app". It writes data on the DynamoDB table "${MiroBannerTermsAcceptersTable}"' + Handler: app.handler + Runtime: nodejs16.x + CodeUri: writeApp/ + Timeout: 10 + Role: !GetAtt MiroBannerTermsWriteFunctionRole.Arn + Environment: + Variables: + TABLE_NAME: !Ref MiroBannerTermsAcceptersTable + + ## API Gateway + MiroBannerTermsAPI: + Type: "AWS::Serverless::Api" + Properties: + Name: + !Join [ + "", + [ + "api-", + !Join [ + "-", + [ + !Ref AWS::StackName, + !Select [ + 4, + !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], + ], + ], + ], + ], + ] + Description: !Sub 'API endpoint for the "Miro Terms Modal app". It handles requests to read/write on the DynamoDB table "${MiroBannerTermsAcceptersTable}"' + StageName: Prod + DefinitionBody: + swagger: "2.0" + info: + title: "MiroBannerTermsAPI" + paths: + /w: + post: + x-amazon-apigateway-integration: + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MiroBannerTermsWriteFunction.Arn}/invocations + passthroughBehavior: "when_no_match" + httpMethod: POST + type: aws_proxy + responses: {} + security: + - sigv4: [] + options: + summary: CORS support + description: | + Enable CORS by returning correct headers + consumes: + - application/json + produces: + - application/json + tags: + - CORS + x-amazon-apigateway-integration: + type: mock + requestTemplates: + application/json: | + { + 'statusCode' : 200 + } + responses: + "default": + statusCode: "200" + responseParameters: + method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control,Pragma'" + method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'" + method.response.header.Access-Control-Allow-Origin: !Join + - "" + - - "'" + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - "'" + responseTemplates: + application/json: | + {} + responses: + "200": + description: Default response for CORS method + headers: + Access-Control-Allow-Headers: + type: "string" + Access-Control-Allow-Methods: + type: "string" + Access-Control-Allow-Origin: + type: "string" + /q: + get: + x-amazon-apigateway-integration: + uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MiroBannerTermsReadFunction.Arn}/invocations + passthroughBehavior: "when_no_match" + httpMethod: POST + type: aws_proxy + responses: {} + security: + - sigv4: [] + options: + summary: CORS support + description: | + Enable CORS by returning correct headers + consumes: + - application/json + produces: + - application/json + tags: + - CORS + x-amazon-apigateway-integration: + type: mock + requestTemplates: + application/json: | + { + 'statusCode' : 200 + } + responses: + "default": + statusCode: "200" + responseParameters: + method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control,Pragma'" + method.response.header.Access-Control-Allow-Methods: "'OPTIONS,GET'" + method.response.header.Access-Control-Allow-Origin: !Join + - "" + - - "'" + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - "'" + responseTemplates: + application/json: | + {} + responses: + "200": + description: Default response for CORS method + headers: + Access-Control-Allow-Headers: + type: "string" + Access-Control-Allow-Methods: + type: "string" + Access-Control-Allow-Origin: + type: "string" + + ## "Read" Lambda Function Invoke Permission + MiroBannerTermsApiInvokePermissionRead: + Type: "AWS::Lambda::Permission" + Properties: + Action: "lambda:InvokeFunction" + FunctionName: !GetAtt MiroBannerTermsReadFunction.Arn + Principal: "apigateway.amazonaws.com" + SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MiroBannerTermsAPI}/*/*/*" + + ## "Write" Lambda Function Invoke Permission + MiroBannerTermsApiInvokePermissionWrite: + Type: "AWS::Lambda::Permission" + Properties: + Action: "lambda:InvokeFunction" + FunctionName: !GetAtt MiroBannerTermsWriteFunction.Arn + Principal: "apigateway.amazonaws.com" + SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MiroBannerTermsAPI}/*/*/*" + +## Take a note of the outputs for deploying the workflow templates in this sample application +Outputs: + S3BucketBaseUrl: + Description: "Base URL of the S3 bucket where the web assets of the Miro app will be hosted" + Value: !Sub "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + ApiBaseURL: + Description: "Base URL of HTTP API endpoint to read and write on the MiroBannerTermsAcceptersTable database" + Value: !Sub "https://${MiroBannerTermsAPI}.execute-api.${AWS::Region}.amazonaws.com" + DynamoDBTableName: + Description: "Name of the DynamoDB table that captures users who have accepted the terms banner in Miro" + Value: !Ref MiroBannerTermsAcceptersTable + S3BucketName: + Description: "Name of the S3 bucket where the web assets of the Miro app will be hosted (app.html, modal.html and variables.js)" + Value: !Ref MiroTermsBannerFrontend diff --git a/examples/terms-modal-banner-dynamodb/webassets/app.html b/examples/terms-modal-banner-dynamodb/webassets/app.html new file mode 100644 index 000000000..964ffd938 --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/webassets/app.html @@ -0,0 +1,128 @@ + + + + + + + + + + + + diff --git a/examples/terms-modal-banner-dynamodb/webassets/modal.html b/examples/terms-modal-banner-dynamodb/webassets/modal.html new file mode 100644 index 000000000..32028ba7d --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/webassets/modal.html @@ -0,0 +1,192 @@ + + + + + + + + + + +
+
+
+ +
+ To use Company Inc.'s Miro boards, please accept the + Usage Policy.
+ Please reach out to your IT administrator for more information on + the security requirements for using Company Inc.'s Miro boards. +
+
+ + + +
+
+
+
+ + + + diff --git a/examples/terms-modal-banner-dynamodb/webassets/variables.js b/examples/terms-modal-banner-dynamodb/webassets/variables.js new file mode 100644 index 000000000..8367f04cc --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/webassets/variables.js @@ -0,0 +1,13 @@ +/* variables.js */ +/* eslint-disable no-unused-vars */ + +var MODAL_URL = 'replace with your "modal.html" URL from AWS S3'; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com/webassets/modal.html';) + +var API_ENDPOINT_BASE_URL = + 'replace with the value of "ApiBaseURL" from your AWS SAM CLI Output'; // keep the single quotes around the value (e.g. 'https://e4g624kyue.execute-api.eu-central-1.amazonaws.com';) + +var SECONDS_TO_WAIT = 3; // Enter value as number (not string) - Enter value as number (not string) - This is the interval in seconds the app will check if the current user has accepted the terms modal. With the default value (3) the app will check every 3 seconds if the user has accepted the modal until the terms modal has been successfully accepted + +var MODAL_WITH = 590; // Enter value as number (not string) - Width of the modal pop-up in pixels - Adjust as desired + +var MODAL_HEIGHT = 300; // Enter value as number (not string) - Height of the modal pop-up in pixels - Adjusted as desired diff --git a/examples/terms-modal-banner-dynamodb/writeApp/app.js b/examples/terms-modal-banner-dynamodb/writeApp/app.js new file mode 100644 index 000000000..01835d981 --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/writeApp/app.js @@ -0,0 +1,70 @@ +/* Example of expected payload for the POST request: { "id": "Miro_User_ID" } */ + +const AWS = require("aws-sdk"); + +exports.handler = async (event) => { + const dynamoDB = new AWS.DynamoDB.DocumentClient(); + const tableName = process.env.TABLE_NAME; + const apiPayload = JSON.parse(event.body); + + const onlyLettersAndNumbers = function (str) { + return /^[A-Za-z0-9]*$/.test(str); + }; + + const responseHeaders = { + "Access-Control-Allow-Headers": "Content-Type,Accept,Cache-Control,Pragma", + "Access-Control-Allow-Origin": "*", // Replace wildcard (*) with your S3 bucket base URL (visible in your AWS SAML CLI Outputs) - See step 2.13 of the PDF guide https://drive.google.com/file/d/13fdsfiTGCBRWSmAv_7BuMBsWfg4_OWlO/view?usp=sharing + "Access-Control-Allow-Methods": "OPTIONS,POST", // Allow only POST request + "Content-Type": "application/json", + }; + + if (Object.getOwnPropertyDescriptor(apiPayload, "id")) { + const userId = apiPayload.id.toString(); + const isValidUserId = onlyLettersAndNumbers(userId); + + if (!isValidUserId || !userId) { + /* Returning a 409 error if the value of the "id" parameter posted contains characters other than a string with only letters and numbers */ + return { + statusCode: 409, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Data" }), + }; + } + + const params = { + TableName: tableName, + Key: { id: userId }, + UpdateExpression: "set hasAcceptedTerms = :hasAcceptedTerms", + ExpressionAttributeValues: { + ":hasAcceptedTerms": "yes", + }, + ReturnValues: "UPDATED_NEW", + }; + + try { + await dynamoDB.update(params).promise(); + return { + statusCode: 200, + //body: JSON.stringify(result.Attributes) + headers: responseHeaders, + body: JSON.stringify({ result: "success" }), + }; + } catch (error) { + console.error("Error updating item:", error); + + /* Returning a 500 error for any other errors */ + return { + statusCode: 500, + headers: responseHeaders, + body: JSON.stringify({ error: "Internal Server Error" }), + }; + } + } else { + /* Returning a 500 error if the "id" parameter was not passed in the posted payload */ + return { + statusCode: 415, + headers: responseHeaders, + body: JSON.stringify({ error: "Invalid Request" }), + }; + } +}; diff --git a/examples/terms-modal-banner-dynamodb/writeApp/package.json b/examples/terms-modal-banner-dynamodb/writeApp/package.json new file mode 100644 index 000000000..77637e6da --- /dev/null +++ b/examples/terms-modal-banner-dynamodb/writeApp/package.json @@ -0,0 +1,15 @@ +{ + "name": "MiroBannerTermsAcceptersWriteApp", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "Luis Colman, Miro Platform Architecture", + "license": "MIT-0", + "devDependencies": { + "aws-sdk": "^2.749.0" + } +} From ce1a8093405a2fb5dd3a21bfcb664a233e63622d Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Mon, 26 Feb 2024 10:53:54 +0100 Subject: [PATCH 14/15] rm the old directory --- examples/terms-modal-banner-dyanmo/.gitignore | 146 ------- examples/terms-modal-banner-dyanmo/LICENSE | 21 -- examples/terms-modal-banner-dyanmo/README.md | 115 ------ .../terms-modal-banner-dyanmo/readApp/app.js | 99 ----- .../readApp/package.json | 15 - .../terms-modal-banner-dyanmo/template.yaml | 356 ------------------ .../webassets/app.html | 128 ------- .../webassets/modal.html | 192 ---------- .../webassets/variables.js | 13 - .../terms-modal-banner-dyanmo/writeApp/app.js | 70 ---- .../writeApp/package.json | 15 - 11 files changed, 1170 deletions(-) delete mode 100644 examples/terms-modal-banner-dyanmo/.gitignore delete mode 100644 examples/terms-modal-banner-dyanmo/LICENSE delete mode 100644 examples/terms-modal-banner-dyanmo/README.md delete mode 100644 examples/terms-modal-banner-dyanmo/readApp/app.js delete mode 100644 examples/terms-modal-banner-dyanmo/readApp/package.json delete mode 100644 examples/terms-modal-banner-dyanmo/template.yaml delete mode 100644 examples/terms-modal-banner-dyanmo/webassets/app.html delete mode 100644 examples/terms-modal-banner-dyanmo/webassets/modal.html delete mode 100644 examples/terms-modal-banner-dyanmo/webassets/variables.js delete mode 100644 examples/terms-modal-banner-dyanmo/writeApp/app.js delete mode 100644 examples/terms-modal-banner-dyanmo/writeApp/package.json diff --git a/examples/terms-modal-banner-dyanmo/.gitignore b/examples/terms-modal-banner-dyanmo/.gitignore deleted file mode 100644 index d9b5e2934..000000000 --- a/examples/terms-modal-banner-dyanmo/.gitignore +++ /dev/null @@ -1,146 +0,0 @@ - -# Created by https://www.gitignore.io/api/osx,node,linux,windows - -### Linux ### -*~ - -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* - -# KDE directory preferences -.directory - -# Linux trash folder which might appear on any partition or disk -.Trash-* - -# .nfs files are created when an open file is removed but is still being accessed -.nfs* - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Typescript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - - -### OSX ### -*.DS_Store -.AppleDouble -.LSOverride - -# Icon must end with two \r -Icon - -# Thumbnails -._* - -# Files that might appear in the root of a volume -.DocumentRevisions-V100 -.fseventsd -.Spotlight-V100 -.TemporaryItems -.Trashes -.VolumeIcon.icns -.com.apple.timemachine.donotpresent - -# Directories potentially created on remote AFP share -.AppleDB -.AppleDesktop -Network Trash Folder -Temporary Items -.apdisk - -### Windows ### -# Windows thumbnail cache files -Thumbs.db -ehthumbs.db -ehthumbs_vista.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Windows Installer files -*.cab -*.msi -*.msm -*.msp - -# Windows shortcuts -*.lnk - - -# End of https://www.gitignore.io/api/osx,node,linux,windows - -# Editor directories and files -.idea -.vscode -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? - -#AWS/SAM -.aws-sam -packaged.yaml -samconfig.toml - -#jbesw-specific -testData/ diff --git a/examples/terms-modal-banner-dyanmo/LICENSE b/examples/terms-modal-banner-dyanmo/LICENSE deleted file mode 100644 index caab4f9ff..000000000 --- a/examples/terms-modal-banner-dyanmo/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 Miro - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/examples/terms-modal-banner-dyanmo/README.md b/examples/terms-modal-banner-dyanmo/README.md deleted file mode 100644 index c74d3ea6f..000000000 --- a/examples/terms-modal-banner-dyanmo/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Miro Terms Modal Banner App (Web-SDK V2 & AWS DynamoDB) - -This app creates a custom modal banner on your Miro boards that you can show to your users/attendees with any desired content and/or call to actions. It is typically used to accept terms and agreements before using a Miro board. - - To understand how to set up the app (including AWS resources needed to run the app) see the -[developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb) on Miro's Developer documentation. - -💸 **Important**: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example. 💸 - -# 👨🏻‍💻 App Demo - -https://github.com/miroapp/app-examples/assets/10428517/7c97412a-b3ac-4811-965b-af992e7ff7f9 - -# 📒 Table of Contents - -- [Support](#support) -- [Included Features](#features) -- [Tools and Technologies](#tools) -- [Prerequisites](#prerequisites) -- [Associated Developer Tutorial](#tutorial) -- [Run the app locally](#run) -- [Folder Structure](#folder) -- [Contributing](#contributing) -- [License](#license) - -# 🙋🏻 Support - -If you have any questions or need assistance setting up this application, please reach out to your Miro Customer Success Manager or dedicated Miro Solutions Engineer. - -# ⚙️ Included Features - -- [Miro Web SDK](https://developers.miro.com/docs/web-sdk-reference) - - [miro.board.ui.canOpenModal()](https://developers.miro.com/docs/websdk-reference-ui#canopenmodal) - - [miro.board.ui.openModal()](https://developers.miro.com/docs/websdk-reference-ui#openmodal) - - [miro.board.ui.closeModal()](https://developers.miro.com/docs/websdk-reference-ui#closemodal) - - [miro.board.getUserInfo()](https://developers.miro.com/docs/websdk-reference-board#getuserinfo) - -# 🛠️ Tools and Technologies - -- [AWS CLI](https://aws.amazon.com/cli/) -- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) -- [AWS CloudFormation](https://aws.amazon.com/cloudformation/) -- [AWS DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Introduction.html) -- [AWS S3](https://docs.aws.amazon.com/s3) -- [AWS Lambda](https://aws.amazon.com/lambda/) -- [AWS API Gateway](https://aws.amazon.com/api-gateway/) - -# ✅ Prerequisites - -- You have a [Miro account](https://miro.com/signup/). -- You're [signed in to Miro](https://miro.com/login/). -- Your Miro account has a [Developer team](https://developers.miro.com/docs/create-a-developer-team). -- [NodeJS 16.x installed](https://nodejs.org/en/download/) -- [AWS CLI](https://aws.amazon.com/cli/) already configured with Administrator permission -- [AWS SAM CLI installed](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) - minimum version 0.48. - -# 📖 Associated Developer Tutorial - -Using AWS S3 you can host your html files and serve them as regular web pages so they can load within Miro. In addition, you can also use AWS DynamoDB to add custom functionality to your Miro app to track which users have already accepted the modal, so that the modal does not re-appear again for those users. In this guide we will guide you on how to achieve this functionality using Miro and AWS DynamoDB. - -> See the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb) on Miro's Developer documentation. - -# 🏃🏽‍♂️ Run the app using AWS S3 - -Once you have finished all of the steps related to AWS in the [developer tutorial](https://developers.miro.com/v2.0/docs/terms-modal-banner-aws-dynamodb), you can then create the Miro app. - -1. In your new Miro app settings, add in the `App URL`. It should end with `webassets/app.html`. -2. Open the [app manifest editor](https://developers.miro.com/docs/manually-create-an-app#step-2-configure-your-app-in-miro) by clicking **Edit in Manifest**. \ - In the app manifest editor, configure the app as follows ⚠️ Note: you will need to change your sdkUri to be your app.html which is hosted in the `webassets` folder of your S3 bucket. Mine is just shown as an example and then click save: - -```yaml -# See https://developers.miro.com/docs/app-manifest on how to use this -appName: s3-modal-banner -sdkVersion: SDK_V2 -sdkUri: >- - https://s3-miro-terms-banner-12345.s3.amazonaws.com/webassets/app.html -scopes: - - identity:read -``` - -3. Go back to your app home page, and under the `Permissions` section, you will see a blue button that says `Install app and get OAuth token`. Click that button. Then click on `Add` as shown in the video below. In the video we install a different app, but the process is the same regardless of the app. - -> ⚠️ We recommend to install your app on a [developer team](https://developers.miro.com/docs/create-a-developer-team) while you are developing or testing apps.⚠️ - -https://github.com/miroapp/app-examples/assets/10428517/588688ed-eb14-4b64-9dbb-66d1c07eea54 - -4. Go to the team in which you installed the app, and open a board. -5. Once you open the board, the modal should appear within a few seconds. -6. If you click accept, you should see a checkmark and then you should not see the modal again when refreshing the page or opening a new board - on that team. -7. You can also check your AWS DynamoDB database under `Explore Items` tab on the left side and then make sure you select your database which you created as part of this guide and then you should see some Items returned which should be the Miro UserID of the user which has clicked on the "accept" button on the terms. - -🎉 That's it. Great job! 🎉 - -# 🗂️ Folder structure - -``` -. -├── readApp -│ └── app.js // Source code for the serverless backend ("Read" database Lambda function) -├── webassets // HTML and JavaScript files for the Miro app. -│ ├── app.html // The code which uses Miro WebSDK to open the modal for the user. -│ └── modal.html // The code which serves as the UI for the terms which the user will accept. -├── writeApp -│ └── app.js // Source code for the serverless backend ("Write" database Lambda function) -├── template.yaml <-- The yaml code used to generate AWS resources via AWS SAM. -``` - -# 🫱🏻‍🫲🏽 Contributing - -If you want to contribute to this example, or any other Miro Open Source project, please review [Miro's contributing guide](https://github.com/miroapp/app-examples/blob/main/CONTRIBUTING.md). - -# 🪪 License - -[MIT License](https://github.com/miroapp/app-examples/blob/main/LICENSE). diff --git a/examples/terms-modal-banner-dyanmo/readApp/app.js b/examples/terms-modal-banner-dyanmo/readApp/app.js deleted file mode 100644 index 9600a32c0..000000000 --- a/examples/terms-modal-banner-dyanmo/readApp/app.js +++ /dev/null @@ -1,99 +0,0 @@ -const AWS = require("aws-sdk"); - -exports.handler = async (event) => { - const dynamoDB = new AWS.DynamoDB.DocumentClient(); - const tableName = process.env.TABLE_NAME; - - const onlyLettersAndNumbers = function (str) { - return /^[A-Za-z0-9]*$/.test(str); - }; - - const responseHeaders = { - "Access-Control-Allow-Headers": "Content-Type,Accept,Cache-Control,Pragma", - "Access-Control-Allow-Origin": "*", // Replace wildcard (*) with your S3 bucket base URL (visible in your AWS SAML CLI Outputs) - See step 2.10 of the PDF guide https://drive.google.com/file/d/13fdsfiTGCBRWSmAv_7BuMBsWfg4_OWlO/view?usp=sharing - "Access-Control-Allow-Methods": "OPTIONS,GET", // Allow only GET request - "Content-Type": "application/json", - }; - - if ( - event && - !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && - !event.queryStringParameters - ) { - /* Returning a 400 error if the URL parameter "u" is not passed in the GET request */ - return { - statusCode: 400, - headers: responseHeaders, - body: JSON.stringify({ error: "Bad Request" }), - }; - } - - if ( - event && - !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && - !!Object.getOwnPropertyDescriptor(event.queryStringParameters, "u") && - event.queryStringParameters.u !== "" - ) { - const userId = event.queryStringParameters.u.toString(); - const isValidUserId = onlyLettersAndNumbers(userId); - - if (!isValidUserId) { - /* Returning a 409 error if the value of the URL parameter "u" passed in the GET request contains characters other than letters and numbers */ - return { - statusCode: 409, - headers: responseHeaders, - body: JSON.stringify({ error: "Invalid Data" }), - }; - } - } else { - return { - statusCode: 415, - headers: responseHeaders, - body: JSON.stringify({ error: "Invalid Request" }), - }; - } - - const userId = event.queryStringParameters.u.toString(); - - const params = { - TableName: tableName, - Key: { - id: userId, - }, - }; - - try { - const data = await dynamoDB.get(params).promise(); - - if ( - data && - !!Object.getOwnPropertyDescriptor(data, "Item") && - !!Object.getOwnPropertyDescriptor(data.Item, "id") && - data.Item.id.toString() === userId - ) { - /* Returning a 200 OK if the value of the URL parameter "u" matches an entry in the MiroBannerTermsAccepters DynamoDB table */ - return { - statusCode: 200, - //body: JSON.stringify(data.Item) - headers: responseHeaders, - body: JSON.stringify({ result: "success" }), - }; - } else { - /* Returning a 404 error if the value of the URL parameter "u" does not match any entry in the DynamoDB table */ - return { - statusCode: 404, - headers: responseHeaders, - body: JSON.stringify({ error: "Not Found" }), - }; - } - } catch (error) { - console.error("Error querying DynamoDB:", error); - - /* Returning a 500 error for any other error not catched above */ - return { - statusCode: 500, - headers: responseHeaders, - body: JSON.stringify({ error: "Internal Server Error" }), - }; - } -}; diff --git a/examples/terms-modal-banner-dyanmo/readApp/package.json b/examples/terms-modal-banner-dyanmo/readApp/package.json deleted file mode 100644 index 6479c9be9..000000000 --- a/examples/terms-modal-banner-dyanmo/readApp/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "MiroBannerTermsAcceptersReadApp", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "Luis Colman, Miro Platform Architecture", - "license": "MIT-0", - "devDependencies": { - "aws-sdk": "^2.749.0" - } -} diff --git a/examples/terms-modal-banner-dyanmo/template.yaml b/examples/terms-modal-banner-dyanmo/template.yaml deleted file mode 100644 index dbc44c7aa..000000000 --- a/examples/terms-modal-banner-dyanmo/template.yaml +++ /dev/null @@ -1,356 +0,0 @@ -AWSTemplateFormatVersion: "2010-09-09" -Transform: "AWS::Serverless-2016-10-31" -Description: Miro Banner Terms Accepters - -Resources: - ## S3 Bucket - MiroTermsBannerFrontend: - Type: AWS::S3::Bucket - Properties: - BucketName: - !Join [ - "", - [ - "s3-", - !Join [ - "-", - [ - "miro-terms-banner-frontend", - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ], - ], - ] - CorsConfiguration: - CorsRules: - - AllowedHeaders: - - "*" - AllowedMethods: - - GET - AllowedOrigins: - - !Join [ - "", - [ - "https://s3-", - !Join [ - "-", - [ - "miro-terms-banner-frontend", - !Select [ - 4, - !Split [ - "-", - !Select [2, !Split ["/", !Ref AWS::StackId]], - ], - ], - ], - ], - ".s3.", - !Ref AWS::Region, - ".amazonaws.com", - ], - ] - PublicAccessBlockConfiguration: - BlockPublicAcls: false - BlockPublicPolicy: false - IgnorePublicAcls: false - RestrictPublicBuckets: false - - ## S3 Bucket Policy - This permission will make the contents of the S3 bucket publicly readable - ProductBucketPolicy: - Type: AWS::S3::BucketPolicy - Properties: - Bucket: !Ref MiroTermsBannerFrontend - PolicyDocument: - Id: PublicReadPolicy - Version: "2012-10-17" - Statement: - - Sid: PublicReadForGetBucketObjects - Effect: Allow - Principal: "*" - Action: s3:GetObject - Resource: !Sub "arn:aws:s3:::${MiroTermsBannerFrontend}/*" - Condition: {} - - ## Database where users who have accepted the Miro Banner will be captured. - ## The "id" will be the numeric Miro User ID, stored as a string. You may use a hashed version of the Miro ID in this table instead (if desired) - MiroBannerTermsAcceptersTable: - Type: "AWS::Serverless::SimpleTable" - Properties: - TableName: - !Join [ - "-", - [ - "miro-terms-banner-accepters-database", - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ] - PrimaryKey: - Name: id - Type: String - - ## IAM Role for the "Read" Lambda Function to query/read the database - MiroBannerTermsReadFunctionRole: - Type: "AWS::IAM::Role" - Properties: - RoleName: MiroBannerTermsReadFunctionRole - AssumeRolePolicyDocument: - Version: "2012-10-17" - Statement: - - Effect: Allow - Principal: - Service: - - lambda.amazonaws.com - Action: "sts:AssumeRole" - Policies: - - PolicyName: MiroBannerTermsDynamoDBReadPolicy - PolicyDocument: - Version: "2012-10-17" - Statement: - - Effect: Allow - Action: - - "dynamodb:GetItem" - Resource: !GetAtt MiroBannerTermsAcceptersTable.Arn - - ## IAM Role for the "Write" Lambda Function to write on the database - MiroBannerTermsWriteFunctionRole: - Type: "AWS::IAM::Role" - Properties: - RoleName: MiroBannerTermsWriteFunctionRole - AssumeRolePolicyDocument: - Version: "2012-10-17" - Statement: - - Effect: Allow - Principal: - Service: - - lambda.amazonaws.com - Action: "sts:AssumeRole" - Policies: - - PolicyName: MiroBannerTermsDynamoDBWritePolicy - PolicyDocument: - Version: "2012-10-17" - Statement: - - Effect: Allow - Action: - - "dynamodb:UpdateItem" - Resource: !GetAtt MiroBannerTermsAcceptersTable.Arn - - ## Lambda "Read" Function - MiroBannerTermsReadFunction: - Type: "AWS::Serverless::Function" - Properties: - FunctionName: - !Join [ - "-", - [ - "MiroBannerTermsReadFunction", - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ] - Description: !Sub 'Lambda function for the "Miro Terms Modal app". It reads data from the DynamoDB table "${MiroBannerTermsAcceptersTable}"' - Handler: app.handler - Runtime: nodejs16.x - CodeUri: readApp/ - Timeout: 10 - Role: !GetAtt MiroBannerTermsReadFunctionRole.Arn - Environment: - Variables: - TABLE_NAME: !Ref MiroBannerTermsAcceptersTable - - ## Lambda "Write" Function - MiroBannerTermsWriteFunction: - Type: "AWS::Serverless::Function" - Properties: - FunctionName: - !Join [ - "-", - [ - "MiroBannerTermsWriteFunction", - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ] - Description: !Sub 'Lambda function for the "Miro Terms Modal app". It writes data on the DynamoDB table "${MiroBannerTermsAcceptersTable}"' - Handler: app.handler - Runtime: nodejs16.x - CodeUri: writeApp/ - Timeout: 10 - Role: !GetAtt MiroBannerTermsWriteFunctionRole.Arn - Environment: - Variables: - TABLE_NAME: !Ref MiroBannerTermsAcceptersTable - - ## API Gateway - MiroBannerTermsAPI: - Type: "AWS::Serverless::Api" - Properties: - Name: - !Join [ - "", - [ - "api-", - !Join [ - "-", - [ - !Ref AWS::StackName, - !Select [ - 4, - !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId]]], - ], - ], - ], - ], - ] - Description: !Sub 'API endpoint for the "Miro Terms Modal app". It handles requests to read/write on the DynamoDB table "${MiroBannerTermsAcceptersTable}"' - StageName: Prod - DefinitionBody: - swagger: "2.0" - info: - title: "MiroBannerTermsAPI" - paths: - /w: - post: - x-amazon-apigateway-integration: - uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MiroBannerTermsWriteFunction.Arn}/invocations - passthroughBehavior: "when_no_match" - httpMethod: POST - type: aws_proxy - responses: {} - security: - - sigv4: [] - options: - summary: CORS support - description: | - Enable CORS by returning correct headers - consumes: - - application/json - produces: - - application/json - tags: - - CORS - x-amazon-apigateway-integration: - type: mock - requestTemplates: - application/json: | - { - 'statusCode' : 200 - } - responses: - "default": - statusCode: "200" - responseParameters: - method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control,Pragma'" - method.response.header.Access-Control-Allow-Methods: "'OPTIONS,POST'" - method.response.header.Access-Control-Allow-Origin: !Join - - "" - - - "'" - - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" - - "'" - responseTemplates: - application/json: | - {} - responses: - "200": - description: Default response for CORS method - headers: - Access-Control-Allow-Headers: - type: "string" - Access-Control-Allow-Methods: - type: "string" - Access-Control-Allow-Origin: - type: "string" - /q: - get: - x-amazon-apigateway-integration: - uri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MiroBannerTermsReadFunction.Arn}/invocations - passthroughBehavior: "when_no_match" - httpMethod: POST - type: aws_proxy - responses: {} - security: - - sigv4: [] - options: - summary: CORS support - description: | - Enable CORS by returning correct headers - consumes: - - application/json - produces: - - application/json - tags: - - CORS - x-amazon-apigateway-integration: - type: mock - requestTemplates: - application/json: | - { - 'statusCode' : 200 - } - responses: - "default": - statusCode: "200" - responseParameters: - method.response.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,Cache-Control,Pragma'" - method.response.header.Access-Control-Allow-Methods: "'OPTIONS,GET'" - method.response.header.Access-Control-Allow-Origin: !Join - - "" - - - "'" - - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" - - "'" - responseTemplates: - application/json: | - {} - responses: - "200": - description: Default response for CORS method - headers: - Access-Control-Allow-Headers: - type: "string" - Access-Control-Allow-Methods: - type: "string" - Access-Control-Allow-Origin: - type: "string" - - ## "Read" Lambda Function Invoke Permission - MiroBannerTermsApiInvokePermissionRead: - Type: "AWS::Lambda::Permission" - Properties: - Action: "lambda:InvokeFunction" - FunctionName: !GetAtt MiroBannerTermsReadFunction.Arn - Principal: "apigateway.amazonaws.com" - SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MiroBannerTermsAPI}/*/*/*" - - ## "Write" Lambda Function Invoke Permission - MiroBannerTermsApiInvokePermissionWrite: - Type: "AWS::Lambda::Permission" - Properties: - Action: "lambda:InvokeFunction" - FunctionName: !GetAtt MiroBannerTermsWriteFunction.Arn - Principal: "apigateway.amazonaws.com" - SourceArn: !Sub "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${MiroBannerTermsAPI}/*/*/*" - -## Take a note of the outputs for deploying the workflow templates in this sample application -Outputs: - S3BucketBaseUrl: - Description: "Base URL of the S3 bucket where the web assets of the Miro app will be hosted" - Value: !Sub "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" - ApiBaseURL: - Description: "Base URL of HTTP API endpoint to read and write on the MiroBannerTermsAcceptersTable database" - Value: !Sub "https://${MiroBannerTermsAPI}.execute-api.${AWS::Region}.amazonaws.com" - DynamoDBTableName: - Description: "Name of the DynamoDB table that captures users who have accepted the terms banner in Miro" - Value: !Ref MiroBannerTermsAcceptersTable - S3BucketName: - Description: "Name of the S3 bucket where the web assets of the Miro app will be hosted (app.html, modal.html and variables.js)" - Value: !Ref MiroTermsBannerFrontend diff --git a/examples/terms-modal-banner-dyanmo/webassets/app.html b/examples/terms-modal-banner-dyanmo/webassets/app.html deleted file mode 100644 index 964ffd938..000000000 --- a/examples/terms-modal-banner-dyanmo/webassets/app.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - - - - - diff --git a/examples/terms-modal-banner-dyanmo/webassets/modal.html b/examples/terms-modal-banner-dyanmo/webassets/modal.html deleted file mode 100644 index 32028ba7d..000000000 --- a/examples/terms-modal-banner-dyanmo/webassets/modal.html +++ /dev/null @@ -1,192 +0,0 @@ - - - - - - - - - - -
-
-
- -
- To use Company Inc.'s Miro boards, please accept the - Usage Policy.
- Please reach out to your IT administrator for more information on - the security requirements for using Company Inc.'s Miro boards. -
-
- - - -
-
-
-
- - - - diff --git a/examples/terms-modal-banner-dyanmo/webassets/variables.js b/examples/terms-modal-banner-dyanmo/webassets/variables.js deleted file mode 100644 index 8367f04cc..000000000 --- a/examples/terms-modal-banner-dyanmo/webassets/variables.js +++ /dev/null @@ -1,13 +0,0 @@ -/* variables.js */ -/* eslint-disable no-unused-vars */ - -var MODAL_URL = 'replace with your "modal.html" URL from AWS S3'; // keep the single quotes around the value (e.g. 'https://miro-terms-banner-021ba44a2fc7.s3.eu-central-1.amazonaws.com/webassets/modal.html';) - -var API_ENDPOINT_BASE_URL = - 'replace with the value of "ApiBaseURL" from your AWS SAM CLI Output'; // keep the single quotes around the value (e.g. 'https://e4g624kyue.execute-api.eu-central-1.amazonaws.com';) - -var SECONDS_TO_WAIT = 3; // Enter value as number (not string) - Enter value as number (not string) - This is the interval in seconds the app will check if the current user has accepted the terms modal. With the default value (3) the app will check every 3 seconds if the user has accepted the modal until the terms modal has been successfully accepted - -var MODAL_WITH = 590; // Enter value as number (not string) - Width of the modal pop-up in pixels - Adjust as desired - -var MODAL_HEIGHT = 300; // Enter value as number (not string) - Height of the modal pop-up in pixels - Adjusted as desired diff --git a/examples/terms-modal-banner-dyanmo/writeApp/app.js b/examples/terms-modal-banner-dyanmo/writeApp/app.js deleted file mode 100644 index 01835d981..000000000 --- a/examples/terms-modal-banner-dyanmo/writeApp/app.js +++ /dev/null @@ -1,70 +0,0 @@ -/* Example of expected payload for the POST request: { "id": "Miro_User_ID" } */ - -const AWS = require("aws-sdk"); - -exports.handler = async (event) => { - const dynamoDB = new AWS.DynamoDB.DocumentClient(); - const tableName = process.env.TABLE_NAME; - const apiPayload = JSON.parse(event.body); - - const onlyLettersAndNumbers = function (str) { - return /^[A-Za-z0-9]*$/.test(str); - }; - - const responseHeaders = { - "Access-Control-Allow-Headers": "Content-Type,Accept,Cache-Control,Pragma", - "Access-Control-Allow-Origin": "*", // Replace wildcard (*) with your S3 bucket base URL (visible in your AWS SAML CLI Outputs) - See step 2.13 of the PDF guide https://drive.google.com/file/d/13fdsfiTGCBRWSmAv_7BuMBsWfg4_OWlO/view?usp=sharing - "Access-Control-Allow-Methods": "OPTIONS,POST", // Allow only POST request - "Content-Type": "application/json", - }; - - if (Object.getOwnPropertyDescriptor(apiPayload, "id")) { - const userId = apiPayload.id.toString(); - const isValidUserId = onlyLettersAndNumbers(userId); - - if (!isValidUserId || !userId) { - /* Returning a 409 error if the value of the "id" parameter posted contains characters other than a string with only letters and numbers */ - return { - statusCode: 409, - headers: responseHeaders, - body: JSON.stringify({ error: "Invalid Data" }), - }; - } - - const params = { - TableName: tableName, - Key: { id: userId }, - UpdateExpression: "set hasAcceptedTerms = :hasAcceptedTerms", - ExpressionAttributeValues: { - ":hasAcceptedTerms": "yes", - }, - ReturnValues: "UPDATED_NEW", - }; - - try { - await dynamoDB.update(params).promise(); - return { - statusCode: 200, - //body: JSON.stringify(result.Attributes) - headers: responseHeaders, - body: JSON.stringify({ result: "success" }), - }; - } catch (error) { - console.error("Error updating item:", error); - - /* Returning a 500 error for any other errors */ - return { - statusCode: 500, - headers: responseHeaders, - body: JSON.stringify({ error: "Internal Server Error" }), - }; - } - } else { - /* Returning a 500 error if the "id" parameter was not passed in the posted payload */ - return { - statusCode: 415, - headers: responseHeaders, - body: JSON.stringify({ error: "Invalid Request" }), - }; - } -}; diff --git a/examples/terms-modal-banner-dyanmo/writeApp/package.json b/examples/terms-modal-banner-dyanmo/writeApp/package.json deleted file mode 100644 index 77637e6da..000000000 --- a/examples/terms-modal-banner-dyanmo/writeApp/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "MiroBannerTermsAcceptersWriteApp", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "Luis Colman, Miro Platform Architecture", - "license": "MIT-0", - "devDependencies": { - "aws-sdk": "^2.749.0" - } -} From a1750d210d6767d1908d147d1aeb7ec168502ac6 Mon Sep 17 00:00:00 2001 From: Horea Porutiu Date: Thu, 29 Feb 2024 11:56:16 +0100 Subject: [PATCH 15/15] template fix for cors error --- .../readApp/app.js | 20 +--------- .../terms-modal-banner-dynamodb/template.yaml | 39 +++++++++++++++++-- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/examples/terms-modal-banner-dynamodb/readApp/app.js b/examples/terms-modal-banner-dynamodb/readApp/app.js index 9600a32c0..5b3bdc510 100644 --- a/examples/terms-modal-banner-dynamodb/readApp/app.js +++ b/examples/terms-modal-banner-dynamodb/readApp/app.js @@ -15,25 +15,7 @@ exports.handler = async (event) => { "Content-Type": "application/json", }; - if ( - event && - !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && - !event.queryStringParameters - ) { - /* Returning a 400 error if the URL parameter "u" is not passed in the GET request */ - return { - statusCode: 400, - headers: responseHeaders, - body: JSON.stringify({ error: "Bad Request" }), - }; - } - - if ( - event && - !!Object.getOwnPropertyDescriptor(event, "queryStringParameters") && - !!Object.getOwnPropertyDescriptor(event.queryStringParameters, "u") && - event.queryStringParameters.u !== "" - ) { + if (event?.queryStringParameters?.u) { const userId = event.queryStringParameters.u.toString(); const isValidUserId = onlyLettersAndNumbers(userId); diff --git a/examples/terms-modal-banner-dynamodb/template.yaml b/examples/terms-modal-banner-dynamodb/template.yaml index dbc44c7aa..56418cc86 100644 --- a/examples/terms-modal-banner-dynamodb/template.yaml +++ b/examples/terms-modal-banner-dynamodb/template.yaml @@ -53,6 +53,26 @@ Resources: ".amazonaws.com", ], ] + - !Join [ + "", + [ + "https://s3-", + !Join [ + "-", + [ + "miro-terms-banner-frontend", + !Select [ + 4, + !Split [ + "-", + !Select [2, !Split ["/", !Ref AWS::StackId]], + ], + ], + ], + ], + ".s3.amazonaws.com", + ], + ] PublicAccessBlockConfiguration: BlockPublicAcls: false BlockPublicPolicy: false @@ -255,7 +275,10 @@ Resources: method.response.header.Access-Control-Allow-Origin: !Join - "" - - "'" - - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - !If + - IsNotUSEast1 + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.amazonaws.com" - "'" responseTemplates: application/json: | @@ -306,7 +329,10 @@ Resources: method.response.header.Access-Control-Allow-Origin: !Join - "" - - "'" - - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - !If + - IsNotUSEast1 + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.amazonaws.com" - "'" responseTemplates: application/json: | @@ -344,7 +370,10 @@ Resources: Outputs: S3BucketBaseUrl: Description: "Base URL of the S3 bucket where the web assets of the Miro app will be hosted" - Value: !Sub "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + Value: !If + - IsNotUSEast1 + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.${AWS::Region}.amazonaws.com" + - Fn::Sub: "https://${MiroTermsBannerFrontend}.s3.amazonaws.com" ApiBaseURL: Description: "Base URL of HTTP API endpoint to read and write on the MiroBannerTermsAcceptersTable database" Value: !Sub "https://${MiroBannerTermsAPI}.execute-api.${AWS::Region}.amazonaws.com" @@ -354,3 +383,7 @@ Outputs: S3BucketName: Description: "Name of the S3 bucket where the web assets of the Miro app will be hosted (app.html, modal.html and variables.js)" Value: !Ref MiroTermsBannerFrontend + +## Condition to adjust URLs based on region (the Default region "us-eat-1" is not added to URLs. For other regions the region is part of the URLs) +Conditions: + IsNotUSEast1: !Not [!Equals [!Ref "AWS::Region", "us-east-1"]]