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..deb27160c --- /dev/null +++ b/examples/terms-modal-banner-s3/README.md @@ -0,0 +1,113 @@ +# 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/6fafc30b-e246-4677-8f5b-cb5396ccdc54 + +# 📒 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://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 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 new file mode 100644 index 000000000..5fbf52eb0 --- /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-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 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..ec6379022 --- /dev/null +++ b/examples/terms-modal-banner-s3/webassets/modal.html @@ -0,0 +1,196 @@ + + + + + + + + + +
+
+
+ +
+ 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..a0563f0be --- /dev/null +++ b/examples/terms-modal-banner-s3/webassets/variables.js @@ -0,0 +1,16 @@ +/* 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