From 95463cdabdaa470256bad5745e5f871d089a1269 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Mon, 17 Jul 2023 21:19:20 +0100
Subject: [PATCH 01/10] feat: Censor with Redact function
---
censor-with-redact/.gitignore | 1 +
censor-with-redact/.prettierrc.json | 6 ++
censor-with-redact/README.md | 37 ++++++++++++
censor-with-redact/package-lock.json | 64 ++++++++++++++++++++
censor-with-redact/package.json | 19 ++++++
censor-with-redact/src/main.js | 41 +++++++++++++
censor-with-redact/static/index.html | 88 ++++++++++++++++++++++++++++
7 files changed, 256 insertions(+)
create mode 100644 censor-with-redact/.gitignore
create mode 100644 censor-with-redact/.prettierrc.json
create mode 100644 censor-with-redact/README.md
create mode 100644 censor-with-redact/package-lock.json
create mode 100644 censor-with-redact/package.json
create mode 100644 censor-with-redact/src/main.js
create mode 100644 censor-with-redact/static/index.html
diff --git a/censor-with-redact/.gitignore b/censor-with-redact/.gitignore
new file mode 100644
index 00000000..b512c09d
--- /dev/null
+++ b/censor-with-redact/.gitignore
@@ -0,0 +1 @@
+node_modules
\ No newline at end of file
diff --git a/censor-with-redact/.prettierrc.json b/censor-with-redact/.prettierrc.json
new file mode 100644
index 00000000..fa51da29
--- /dev/null
+++ b/censor-with-redact/.prettierrc.json
@@ -0,0 +1,6 @@
+{
+ "trailingComma": "es5",
+ "tabWidth": 2,
+ "semi": false,
+ "singleQuote": true
+}
diff --git a/censor-with-redact/README.md b/censor-with-redact/README.md
new file mode 100644
index 00000000..1912ca3e
--- /dev/null
+++ b/censor-with-redact/README.md
@@ -0,0 +1,37 @@
+# Censor with Redact Function
+
+This function allows you to redact sensitive information from a provided text string. It uses the Redact API by Pangea to censor the text. You can use this function to ensure any text you process does not unintentionally reveal sensitive or personally identifiable information.
+
+## Environment Variables
+
+To ensure the function operates as intended, ensure the following variables are set:
+
+- **PANGEA_REDACT_TOKEN**: This is your access token for the Pangea Redact API.
+
+## Usage
+
+This function supports two types of requests:
+
+1. **GET Request**
+
+ - **Request Type:** GET
+ - **Response:**
+ - On success, the function will respond with an HTML page that can be used to enter text and see the redacted result. The HTML file is located in the 'static' folder, and it's named 'index.html'.
+
+2. **Redact Text**
+
+ - **Request Type:** POST
+ - **Body:**
+ - The plain text string that you want to redact.
+ - **Response:**
+ - On success, the function will respond with the text string with sensitive information redacted.
+
+## Front-End Implementation
+
+The function includes a simple front-end HTML page as an example of how you could use the function from a web page. The front-end sends a POST request to the function when the 'Censor' button is clicked, and the result is displayed on the page.
+
+The HTML file (index.html) is located in the 'static' directory. It uses Alpine.js for interactivity and the @appwrite.io/pink CSS framework for styling. The page includes an input field where the user can type a message, a 'Censor' button to submit the message for redaction, and an area to display the redacted message.
+
+## Error Handling
+
+If the required environment variable `PANGEA_REDACT_TOKEN` is not set, the function will throw an error. Similarly, if a POST request is made without any body content, the function will return an HTTP 400 error with the message "Missing body with a prompt.".
\ No newline at end of file
diff --git a/censor-with-redact/package-lock.json b/censor-with-redact/package-lock.json
new file mode 100644
index 00000000..11170539
--- /dev/null
+++ b/censor-with-redact/package-lock.json
@@ -0,0 +1,64 @@
+{
+ "name": "censor-with-redact",
+ "version": "1.0.0",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "censor-with-redact",
+ "version": "1.0.0",
+ "license": "ISC",
+ "dependencies": {
+ "undici": "^5.22.1"
+ },
+ "devDependencies": {
+ "prettier": "^3.0.0"
+ }
+ },
+ "node_modules/busboy": {
+ "version": "1.6.0",
+ "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
+ "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
+ "dependencies": {
+ "streamsearch": "^1.1.0"
+ },
+ "engines": {
+ "node": ">=10.16.0"
+ }
+ },
+ "node_modules/prettier": {
+ "version": "3.0.0",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz",
+ "integrity": "sha512-zBf5eHpwHOGPC47h0zrPyNn+eAEIdEzfywMoYn2XPi0P44Zp0tSq64rq0xAREh4auw2cJZHo9QUob+NqCQky4g==",
+ "dev": true,
+ "bin": {
+ "prettier": "bin/prettier.cjs"
+ },
+ "engines": {
+ "node": ">=14"
+ },
+ "funding": {
+ "url": "https://github.com/prettier/prettier?sponsor=1"
+ }
+ },
+ "node_modules/streamsearch": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
+ "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
+ "engines": {
+ "node": ">=10.0.0"
+ }
+ },
+ "node_modules/undici": {
+ "version": "5.22.1",
+ "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz",
+ "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==",
+ "dependencies": {
+ "busboy": "^1.6.0"
+ },
+ "engines": {
+ "node": ">=14.0"
+ }
+ }
+ }
+}
diff --git a/censor-with-redact/package.json b/censor-with-redact/package.json
new file mode 100644
index 00000000..b8684cff
--- /dev/null
+++ b/censor-with-redact/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "censor-with-redact",
+ "version": "1.0.0",
+ "description": "",
+ "main": "src/main.js",
+ "type": "module",
+ "scripts": {
+ "format": "prettier --write src/**/*.js"
+ },
+ "keywords": [],
+ "author": "",
+ "license": "ISC",
+ "devDependencies": {
+ "prettier": "^3.0.0"
+ },
+ "dependencies": {
+ "undici": "^5.22.1"
+ }
+}
diff --git a/censor-with-redact/src/main.js b/censor-with-redact/src/main.js
new file mode 100644
index 00000000..18fb802c
--- /dev/null
+++ b/censor-with-redact/src/main.js
@@ -0,0 +1,41 @@
+import fs from 'fs'
+import path from 'path'
+import { fileURLToPath } from 'url'
+
+const __filename = fileURLToPath(import.meta.url)
+const __dirname = path.dirname(__filename)
+
+const staticFolder = path.join(__dirname, '../static')
+
+export default async ({ req, res }) => {
+ const { PANGEA_REDACT_TOKEN } = process.env
+
+ if (!PANGEA_REDACT_TOKEN) {
+ throw new Error('Function is missing required environment variables.')
+ }
+
+ if (req.method === 'GET') {
+ const html = fs
+ .readFileSync(path.join(staticFolder, 'index.html'))
+ .toString()
+ return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' })
+ }
+
+ if (!req.bodyString) {
+ return res.send('Missing body with a prompt.', 400)
+ }
+
+ const response = await fetch(`https://redact.aws.eu.pangea.cloud/v1/redact`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${PANGEA_REDACT_TOKEN}`,
+ },
+ body: JSON.stringify({
+ text: req.bodyString,
+ }),
+ })
+
+ const data = /** @type {*} */ (await response.json())
+ return res.send(data.result.redacted_text)
+}
diff --git a/censor-with-redact/static/index.html b/censor-with-redact/static/index.html
new file mode 100644
index 00000000..a8177be4
--- /dev/null
+++ b/censor-with-redact/static/index.html
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+ Censor with Redact API Demo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Censor with Redact API Demo
+
+
+
+ This is demo application. You can ue this app to ensure
+ implementation with Redact API works properly. Use input below to
+ enter text and get censored message as response.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Redact API:
+
+
+
+
+
+
+
+
+
+
+
+
+
From 5d9d7ba219c077e64d27023ea6bd739dbf7effd0 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 18 Jul 2023 12:49:17 +0100
Subject: [PATCH 02/10] chore: .gitignore
---
censor-with-redact/.gitignore | 131 +++++++++++++++++++++++++++++++++-
1 file changed, 130 insertions(+), 1 deletion(-)
diff --git a/censor-with-redact/.gitignore b/censor-with-redact/.gitignore
index b512c09d..6a7d6d8e 100644
--- a/censor-with-redact/.gitignore
+++ b/censor-with-redact/.gitignore
@@ -1 +1,130 @@
-node_modules
\ No newline at end of file
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+lerna-debug.log*
+.pnpm-debug.log*
+
+# Diagnostic reports (https://nodejs.org/api/report.html)
+report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
+
+# 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
+*.lcov
+
+# nyc test coverage
+.nyc_output
+
+# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
+.grunt
+
+# Bower dependency directory (https://bower.io/)
+bower_components
+
+# node-waf configuration
+.lock-wscript
+
+# Compiled binary addons (https://nodejs.org/api/addons.html)
+build/Release
+
+# Dependency directories
+node_modules/
+jspm_packages/
+
+# Snowpack dependency directory (https://snowpack.dev/)
+web_modules/
+
+# TypeScript cache
+*.tsbuildinfo
+
+# Optional npm cache directory
+.npm
+
+# Optional eslint cache
+.eslintcache
+
+# Optional stylelint cache
+.stylelintcache
+
+# Microbundle cache
+.rpt2_cache/
+.rts2_cache_cjs/
+.rts2_cache_es/
+.rts2_cache_umd/
+
+# Optional REPL history
+.node_repl_history
+
+# Output of 'npm pack'
+*.tgz
+
+# Yarn Integrity file
+.yarn-integrity
+
+# dotenv environment variable files
+.env
+.env.development.local
+.env.test.local
+.env.production.local
+.env.local
+
+# parcel-bundler cache (https://parceljs.org/)
+.cache
+.parcel-cache
+
+# Next.js build output
+.next
+out
+
+# Nuxt.js build / generate output
+.nuxt
+dist
+
+# Gatsby files
+.cache/
+# Comment in the public line in if your project uses Gatsby and not Next.js
+# https://nextjs.org/blog/next-9-1#public-directory-support
+# public
+
+# vuepress build output
+.vuepress/dist
+
+# vuepress v2.x temp and cache directory
+.temp
+.cache
+
+# Docusaurus cache and generated files
+.docusaurus
+
+# Serverless directories
+.serverless/
+
+# FuseBox cache
+.fusebox/
+
+# DynamoDB Local files
+.dynamodb/
+
+# TernJS port file
+.tern-port
+
+# Stores VSCode versions used for testing VSCode extensions
+.vscode-test
+
+# yarn v2
+.yarn/cache
+.yarn/unplugged
+.yarn/build-state.yml
+.yarn/install-state.gz
+.pnp.*
\ No newline at end of file
From e0a0a9986dd7b5ee81dc3399283ff0b6be8bdab6 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Wed, 19 Jul 2023 10:58:25 +0100
Subject: [PATCH 03/10] chore: add semis, del pjson extras
---
censor-with-redact/.prettierrc.json | 2 +-
censor-with-redact/package.json | 2 --
censor-with-redact/src/main.js | 31 ++++++++++++++---------------
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/censor-with-redact/.prettierrc.json b/censor-with-redact/.prettierrc.json
index fa51da29..0a725205 100644
--- a/censor-with-redact/.prettierrc.json
+++ b/censor-with-redact/.prettierrc.json
@@ -1,6 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
- "semi": false,
+ "semi": true,
"singleQuote": true
}
diff --git a/censor-with-redact/package.json b/censor-with-redact/package.json
index b8684cff..39215882 100644
--- a/censor-with-redact/package.json
+++ b/censor-with-redact/package.json
@@ -8,8 +8,6 @@
"format": "prettier --write src/**/*.js"
},
"keywords": [],
- "author": "",
- "license": "ISC",
"devDependencies": {
"prettier": "^3.0.0"
},
diff --git a/censor-with-redact/src/main.js b/censor-with-redact/src/main.js
index 18fb802c..faa8ea98 100644
--- a/censor-with-redact/src/main.js
+++ b/censor-with-redact/src/main.js
@@ -1,28 +1,27 @@
-import fs from 'fs'
-import path from 'path'
-import { fileURLToPath } from 'url'
+import fs from 'fs';
+import path from 'path';
+import { fileURLToPath } from 'url';
-const __filename = fileURLToPath(import.meta.url)
-const __dirname = path.dirname(__filename)
-
-const staticFolder = path.join(__dirname, '../static')
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const staticFolder = path.join(__dirname, '../static');
export default async ({ req, res }) => {
- const { PANGEA_REDACT_TOKEN } = process.env
+ const { PANGEA_REDACT_TOKEN } = process.env;
if (!PANGEA_REDACT_TOKEN) {
- throw new Error('Function is missing required environment variables.')
+ throw new Error('Function is missing required environment variables.');
}
if (req.method === 'GET') {
const html = fs
.readFileSync(path.join(staticFolder, 'index.html'))
- .toString()
- return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' })
+ .toString();
+ return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
}
if (!req.bodyString) {
- return res.send('Missing body with a prompt.', 400)
+ return res.send('Missing body with a prompt.', 400);
}
const response = await fetch(`https://redact.aws.eu.pangea.cloud/v1/redact`, {
@@ -34,8 +33,8 @@ export default async ({ req, res }) => {
body: JSON.stringify({
text: req.bodyString,
}),
- })
+ });
- const data = /** @type {*} */ (await response.json())
- return res.send(data.result.redacted_text)
-}
+ const data = /** @type {*} */ (await response.json());
+ return res.send(data.result.redacted_text);
+};
From 6079cccdce94ed27dd8b9d638145263ba2b0ed0d Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Thu, 20 Jul 2023 10:34:18 +0100
Subject: [PATCH 04/10] chore: new structure
---
{censor-with-redact => node/censor-with-redact}/.gitignore | 0
{censor-with-redact => node/censor-with-redact}/.prettierrc.json | 0
{censor-with-redact => node/censor-with-redact}/README.md | 0
{censor-with-redact => node/censor-with-redact}/package-lock.json | 0
{censor-with-redact => node/censor-with-redact}/package.json | 0
{censor-with-redact => node/censor-with-redact}/src/main.js | 0
{censor-with-redact => node/censor-with-redact}/static/index.html | 0
7 files changed, 0 insertions(+), 0 deletions(-)
rename {censor-with-redact => node/censor-with-redact}/.gitignore (100%)
rename {censor-with-redact => node/censor-with-redact}/.prettierrc.json (100%)
rename {censor-with-redact => node/censor-with-redact}/README.md (100%)
rename {censor-with-redact => node/censor-with-redact}/package-lock.json (100%)
rename {censor-with-redact => node/censor-with-redact}/package.json (100%)
rename {censor-with-redact => node/censor-with-redact}/src/main.js (100%)
rename {censor-with-redact => node/censor-with-redact}/static/index.html (100%)
diff --git a/censor-with-redact/.gitignore b/node/censor-with-redact/.gitignore
similarity index 100%
rename from censor-with-redact/.gitignore
rename to node/censor-with-redact/.gitignore
diff --git a/censor-with-redact/.prettierrc.json b/node/censor-with-redact/.prettierrc.json
similarity index 100%
rename from censor-with-redact/.prettierrc.json
rename to node/censor-with-redact/.prettierrc.json
diff --git a/censor-with-redact/README.md b/node/censor-with-redact/README.md
similarity index 100%
rename from censor-with-redact/README.md
rename to node/censor-with-redact/README.md
diff --git a/censor-with-redact/package-lock.json b/node/censor-with-redact/package-lock.json
similarity index 100%
rename from censor-with-redact/package-lock.json
rename to node/censor-with-redact/package-lock.json
diff --git a/censor-with-redact/package.json b/node/censor-with-redact/package.json
similarity index 100%
rename from censor-with-redact/package.json
rename to node/censor-with-redact/package.json
diff --git a/censor-with-redact/src/main.js b/node/censor-with-redact/src/main.js
similarity index 100%
rename from censor-with-redact/src/main.js
rename to node/censor-with-redact/src/main.js
diff --git a/censor-with-redact/static/index.html b/node/censor-with-redact/static/index.html
similarity index 100%
rename from censor-with-redact/static/index.html
rename to node/censor-with-redact/static/index.html
From a685a0f72a6e0705f0868b38a22df2384c740086 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Thu, 20 Jul 2023 12:03:20 +0100
Subject: [PATCH 05/10] chore: prettier script
---
node/censor-with-redact/package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/node/censor-with-redact/package.json b/node/censor-with-redact/package.json
index 39215882..c18e9ebe 100644
--- a/node/censor-with-redact/package.json
+++ b/node/censor-with-redact/package.json
@@ -5,7 +5,7 @@
"main": "src/main.js",
"type": "module",
"scripts": {
- "format": "prettier --write src/**/*.js"
+ "format": "prettier --write ."
},
"keywords": [],
"devDependencies": {
From a9da3421f472a8ca5a05fa950b7a5f4fb41edd8b Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Mon, 24 Jul 2023 11:38:51 +0100
Subject: [PATCH 06/10] docs: new readme
---
node/censor-with-redact/README.md | 73 +++++++++++++++++++++----------
1 file changed, 51 insertions(+), 22 deletions(-)
diff --git a/node/censor-with-redact/README.md b/node/censor-with-redact/README.md
index 1912ca3e..eb039dd6 100644
--- a/node/censor-with-redact/README.md
+++ b/node/censor-with-redact/README.md
@@ -1,37 +1,66 @@
-# Censor with Redact Function
+# ⚡ Censor with Redact Function
-This function allows you to redact sensitive information from a provided text string. It uses the Redact API by Pangea to censor the text. You can use this function to ensure any text you process does not unintentionally reveal sensitive or personally identifiable information.
+Cesnor sensitive information from a provided text string using Redact API by Pangea.
-## Environment Variables
+## 🧰 Usage
-To ensure the function operates as intended, ensure the following variables are set:
+### `GET`
-- **PANGEA_REDACT_TOKEN**: This is your access token for the Pangea Redact API.
+An HTML form page that can be used to enter text and see the redacted result.
-## Usage
-This function supports two types of requests:
+**Response**
-1. **GET Request**
+Sample `200` Response:
- - **Request Type:** GET
- - **Response:**
- - On success, the function will respond with an HTML page that can be used to enter text and see the redacted result. The HTML file is located in the 'static' folder, and it's named 'index.html'.
+```text
+The HTML form
+```
-2. **Redact Text**
+### `POST`
- - **Request Type:** POST
- - **Body:**
- - The plain text string that you want to redact.
- - **Response:**
- - On success, the function will respond with the text string with sensitive information redacted.
+Returns the supplied text string with sensitive information redacted.
-## Front-End Implementation
+**Parameters**
-The function includes a simple front-end HTML page as an example of how you could use the function from a web page. The front-end sends a POST request to the function when the 'Censor' button is clicked, and the result is displayed on the page.
+| Name | Description | Location | Type | Sample Value |
+|--------|----------------|-------------|--------|-----------------------------------------------------|
+| N/A | Text to redact | Text Body | String | `Hello! My email address is dennis.nedry@ingen.com` |
-The HTML file (index.html) is located in the 'static' directory. It uses Alpine.js for interactivity and the @appwrite.io/pink CSS framework for styling. The page includes an input field where the user can type a message, a 'Censor' button to submit the message for redaction, and an area to display the redacted message.
+**Response**
-## Error Handling
+Sample `200` Response:
-If the required environment variable `PANGEA_REDACT_TOKEN` is not set, the function will throw an error. Similarly, if a POST request is made without any body content, the function will return an HTTP 400 error with the message "Missing body with a prompt.".
\ No newline at end of file
+Content-Type: ``
+```text
+Hello! my email address is
+```
+
+
+Sample `400` Response:
+
+```text
+Missing body with a prompt.
+```
+
+## ⚙️ Configuration
+
+| Setting | Value |
+|-------------------|------------------|
+| Runtime | Node (18.0) |
+| Entrypoint | `src/main.js` |
+| Build Commands | `npm install` |
+| Permissions | `any` |
+| Timeout (Seconds) | 15 |
+
+## 🔒 Environment Variables
+
+### PANGEA_REDACT_TOKEN
+
+Access token for the Pangea Redact API
+
+| Question | Answer |
+|----------------|------------------------|
+| Required | Yes |
+| Sample Value | `d1efbad42adgj` |
+| Documentation | [Pangea: Configuration](https://pangea.cloud/docs/redact/getting-started/configuration) |
From 002322d8baecf5afb6fe13852243ad3fe59b4ce1 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Thu, 27 Jul 2023 17:08:27 +0100
Subject: [PATCH 07/10] chore: use json, add undici
---
node/censor-with-redact/README.md | 63 ++++++++++++++---------------
node/censor-with-redact/src/main.js | 17 ++++----
2 files changed, 39 insertions(+), 41 deletions(-)
diff --git a/node/censor-with-redact/README.md b/node/censor-with-redact/README.md
index eb039dd6..74320541 100644
--- a/node/censor-with-redact/README.md
+++ b/node/censor-with-redact/README.md
@@ -1,4 +1,4 @@
-# ⚡ Censor with Redact Function
+# 🛑 Censor with Redact Function
Cesnor sensitive information from a provided text string using Redact API by Pangea.
@@ -6,16 +6,7 @@ Cesnor sensitive information from a provided text string using Redact API by Pan
### `GET`
-An HTML form page that can be used to enter text and see the redacted result.
-
-
-**Response**
-
-Sample `200` Response:
-
-```text
-The HTML form
-```
+Returns an HTML form page that can be used to enter text and see the redacted result.
### `POST`
@@ -23,44 +14,52 @@ Returns the supplied text string with sensitive information redacted.
**Parameters**
-| Name | Description | Location | Type | Sample Value |
-|--------|----------------|-------------|--------|-----------------------------------------------------|
-| N/A | Text to redact | Text Body | String | `Hello! My email address is dennis.nedry@ingen.com` |
+| Name | Description | Location | Type | Sample Value |
+| ------------ | --------------------------- | -------- | ------------------ | -------------------------------------------- |
+| Content-Type | Content type of the request | Header | `application/json` | N/A |
+| text | Text to redact | Body | String | `My email address is dennis.nedry@ingen.com` |
**Response**
Sample `200` Response:
Content-Type: ``
-```text
-Hello! my email address is
-```
+```json
+{
+ "ok": true,
+ "redacted": "My email address is "
+}
+```
Sample `400` Response:
-```text
-Missing body with a prompt.
+```json
+{
+ "ok": false,
+ "error": "Missing required field: text."
+}
+
```
## ⚙️ Configuration
-| Setting | Value |
-|-------------------|------------------|
-| Runtime | Node (18.0) |
-| Entrypoint | `src/main.js` |
-| Build Commands | `npm install` |
-| Permissions | `any` |
-| Timeout (Seconds) | 15 |
+| Setting | Value |
+| ----------------- | ------------- |
+| Runtime | Node (18.0) |
+| Entrypoint | `src/main.js` |
+| Build Commands | `npm install` |
+| Permissions | `any` |
+| Timeout (Seconds) | 15 |
## 🔒 Environment Variables
### PANGEA_REDACT_TOKEN
-Access token for the Pangea Redact API
+Access token for the Pangea Redact API
-| Question | Answer |
-|----------------|------------------------|
-| Required | Yes |
-| Sample Value | `d1efbad42adgj` |
-| Documentation | [Pangea: Configuration](https://pangea.cloud/docs/redact/getting-started/configuration) |
+| Question | Answer |
+| ------------- | --------------------------------------------------------------------------------------- |
+| Required | Yes |
+| Sample Value | `d1efbad42adgj` |
+| Documentation | [Pangea: Configuration](https://pangea.cloud/docs/redact/getting-started/configuration) |
diff --git a/node/censor-with-redact/src/main.js b/node/censor-with-redact/src/main.js
index faa8ea98..b25cbe4a 100644
--- a/node/censor-with-redact/src/main.js
+++ b/node/censor-with-redact/src/main.js
@@ -1,16 +1,15 @@
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
+import { fetch } from 'undici';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const staticFolder = path.join(__dirname, '../static');
export default async ({ req, res }) => {
- const { PANGEA_REDACT_TOKEN } = process.env;
-
- if (!PANGEA_REDACT_TOKEN) {
- throw new Error('Function is missing required environment variables.');
+ if (!process.env.PANGEA_REDACT_TOKEN) {
+ throw new Error('Missing required environment variables.');
}
if (req.method === 'GET') {
@@ -20,21 +19,21 @@ export default async ({ req, res }) => {
return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
}
- if (!req.bodyString) {
- return res.send('Missing body with a prompt.', 400);
+ if (!req.body.text) {
+ return res.json({ ok: false, error: 'Missing require field: text.' }, 400);
}
const response = await fetch(`https://redact.aws.eu.pangea.cloud/v1/redact`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
- Authorization: `Bearer ${PANGEA_REDACT_TOKEN}`,
+ Authorization: `Bearer ${process.env.PANGEA_REDACT_TOKEN}`,
},
body: JSON.stringify({
- text: req.bodyString,
+ text: req.body.text,
}),
});
const data = /** @type {*} */ (await response.json());
- return res.send(data.result.redacted_text);
+ return res.json({ ok: true, redacted: data.result.redacted_text });
};
From 8d6bc9737da0e96da216ae928db5649e2efa8692 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 28 Jul 2023 12:19:13 +0100
Subject: [PATCH 08/10] chore: new utils
---
node/censor-with-redact/src/main.js | 25 ++++++++------------
node/censor-with-redact/src/utils.js | 34 ++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 16 deletions(-)
create mode 100644 node/censor-with-redact/src/utils.js
diff --git a/node/censor-with-redact/src/main.js b/node/censor-with-redact/src/main.js
index b25cbe4a..ea14925d 100644
--- a/node/censor-with-redact/src/main.js
+++ b/node/censor-with-redact/src/main.js
@@ -1,26 +1,19 @@
-import fs from 'fs';
-import path from 'path';
-import { fileURLToPath } from 'url';
import { fetch } from 'undici';
-
-const __filename = fileURLToPath(import.meta.url);
-const __dirname = path.dirname(__filename);
-const staticFolder = path.join(__dirname, '../static');
+import { getStaticFile, throwIfMissing } from './utils';
export default async ({ req, res }) => {
- if (!process.env.PANGEA_REDACT_TOKEN) {
- throw new Error('Missing required environment variables.');
- }
+ throwIfMissing(process.env, ['PANGEA_REDACT_TOKEN']);
if (req.method === 'GET') {
- const html = fs
- .readFileSync(path.join(staticFolder, 'index.html'))
- .toString();
- return res.send(html, 200, { 'Content-Type': 'text/html; charset=utf-8' });
+ return res.send(getStaticFile('index.html'), 200, {
+ 'Content-Type': 'text/html; charset=utf-8',
+ });
}
- if (!req.body.text) {
- return res.json({ ok: false, error: 'Missing require field: text.' }, 400);
+ try {
+ throwIfMissing(req.body, ['text']);
+ } catch (err) {
+ return res.json({ ok: false, error: err.message }, 400);
}
const response = await fetch(`https://redact.aws.eu.pangea.cloud/v1/redact`, {
diff --git a/node/censor-with-redact/src/utils.js b/node/censor-with-redact/src/utils.js
new file mode 100644
index 00000000..5b93ba58
--- /dev/null
+++ b/node/censor-with-redact/src/utils.js
@@ -0,0 +1,34 @@
+import path from 'path';
+import { fileURLToPath } from 'url';
+import fs from 'fs';
+
+/**
+ * Throws an error if any of the keys are missing from the object
+ * @param {*} obj
+ * @param {string[]} keys
+ * @throws {Error}
+ */
+export function throwIfMissing(obj, keys) {
+ const missing = [];
+ for (let key of keys) {
+ if (!(key in obj) || !obj[key]) {
+ missing.push(key);
+ }
+ }
+ if (missing.length > 0) {
+ throw new Error(`Missing required fields: ${missing.join(', ')}`);
+ }
+}
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const staticFolder = path.join(__dirname, '../static');
+
+/**
+ * Returns the contents of a file in the static folder
+ * @param {string} fileName
+ * @returns {string} Contents of static/{fileName}
+ */
+export function getStaticFile(fileName) {
+ return fs.readFileSync(path.join(staticFolder, fileName)).toString();
+}
From 75a8cdf11e9869376748e79535cf06a1dd6eec5c Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 28 Jul 2023 14:26:44 +0100
Subject: [PATCH 09/10] fix: esm import
---
node/censor-with-redact/src/main.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/node/censor-with-redact/src/main.js b/node/censor-with-redact/src/main.js
index ea14925d..e39ae297 100644
--- a/node/censor-with-redact/src/main.js
+++ b/node/censor-with-redact/src/main.js
@@ -1,5 +1,5 @@
import { fetch } from 'undici';
-import { getStaticFile, throwIfMissing } from './utils';
+import { getStaticFile, throwIfMissing } from './utils.js';
export default async ({ req, res }) => {
throwIfMissing(process.env, ['PANGEA_REDACT_TOKEN']);
From f26a0e3e2aeac40822d0c89062364e24cd745576 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matej=20Ba=C4=8Do?=
Date: Sun, 30 Jul 2023 18:37:34 +0000
Subject: [PATCH 10/10] PR review changes
---
node/censor-with-redact/README.md | 8 ++++----
node/censor-with-redact/static/index.html | 16 ++++++++++------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/node/censor-with-redact/README.md b/node/censor-with-redact/README.md
index 74320541..ddc724db 100644
--- a/node/censor-with-redact/README.md
+++ b/node/censor-with-redact/README.md
@@ -1,4 +1,4 @@
-# 🛑 Censor with Redact Function
+# 🤐 Node.js Censor with Redact Function
Cesnor sensitive information from a provided text string using Redact API by Pangea.
@@ -6,7 +6,7 @@ Cesnor sensitive information from a provided text string using Redact API by Pan
### `GET`
-Returns an HTML form page that can be used to enter text and see the redacted result.
+HTML form for interacting with the model.
### `POST`
@@ -17,7 +17,7 @@ Returns the supplied text string with sensitive information redacted.
| Name | Description | Location | Type | Sample Value |
| ------------ | --------------------------- | -------- | ------------------ | -------------------------------------------- |
| Content-Type | Content type of the request | Header | `application/json` | N/A |
-| text | Text to redact | Body | String | `My email address is dennis.nedry@ingen.com` |
+| text | Text to redact | Body | String | `My email address is myname2000@gmail.com` |
**Response**
@@ -61,5 +61,5 @@ Access token for the Pangea Redact API
| Question | Answer |
| ------------- | --------------------------------------------------------------------------------------- |
| Required | Yes |
-| Sample Value | `d1efbad42adgj` |
+| Sample Value | `pts_7p4...5wl4` |
| Documentation | [Pangea: Configuration](https://pangea.cloud/docs/redact/getting-started/configuration) |
diff --git a/node/censor-with-redact/static/index.html b/node/censor-with-redact/static/index.html
index a8177be4..af43985f 100644
--- a/node/censor-with-redact/static/index.html
+++ b/node/censor-with-redact/static/index.html
@@ -7,18 +7,22 @@
Censor with Redact API Demo