Skip to content

Commit

Permalink
fix typo in directory name
Browse files Browse the repository at this point in the history
  • Loading branch information
horeaporutiu committed Feb 26, 2024
1 parent 6593494 commit 0b647cb
Show file tree
Hide file tree
Showing 11 changed files with 1,170 additions and 0 deletions.
146 changes: 146 additions & 0 deletions examples/terms-modal-banner-dynamodb/.gitignore
Original file line number Diff line number Diff line change
@@ -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/
21 changes: 21 additions & 0 deletions examples/terms-modal-banner-dynamodb/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
115 changes: 115 additions & 0 deletions examples/terms-modal-banner-dynamodb/README.md
Original file line number Diff line number Diff line change
@@ -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.

<b> 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.</b>

💸 **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 <a name="features"></a>

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 <a name="features"></a>

- [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 <a name="tools"></a>

- [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 <a name="prerequisites"></a>

- 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 <a name="tutorial"></a>

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 <a name="run"></a>

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 <b> ⚠️ 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 </b> 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. <b>In the video we install a different app, but the process is the same regardless of the app.</b>

> ⚠️ 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 <a name="folder"></a>

```
.
├── 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 <a name="contributing"></a>
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 <a name="license"></a>
[MIT License](https://github.com/miroapp/app-examples/blob/main/LICENSE).
99 changes: 99 additions & 0 deletions examples/terms-modal-banner-dynamodb/readApp/app.js
Original file line number Diff line number Diff line change
@@ -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" }),
};
}
};
Loading

0 comments on commit 0b647cb

Please sign in to comment.