Skip to content

Commit

Permalink
Merge pull request #1440 from prosopo/release/2.1.4
Browse files Browse the repository at this point in the history
Release 2.1.4
  • Loading branch information
forgetso authored Oct 10, 2024
2 parents 482e303 + a4a1c7c commit 8f50b6d
Show file tree
Hide file tree
Showing 116 changed files with 1,759 additions and 2,614 deletions.
1 change: 1 addition & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ jobs:
git config user.email "dev@prosopo.io"
# checkout the src branch
git fetch --all
git checkout ${{ github.event.inputs.src }}
INTERIM="${{ github.event.inputs.interim}}"
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: cypress
on:
pull_request:
branches: [main, dev, staging, release/*]
types:
types:
- opened # when a PR is opened
- synchronize # when a PR is pushed to
- reopened # when a PR is reopened
Expand Down Expand Up @@ -106,6 +106,7 @@ jobs:
cp demos/client-example-server/env.development demos/client-example-server/.env.test
cp demos/client-example/env.development demos/client-example/.env.test
cp demos/client-bundle-example/env.development demos/client-example/.env.test
cp dev/scripts/env.test .env.test
cp dev/scripts/env.test dev/scripts/.env.test
cp dev/scripts/env.test packages/cli/.env.test
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ jobs:
cp demos/client-example-server/env.development demos/client-example-server/.env.test
cp demos/client-example/env.development demos/client-example/.env.test
cp demos/client-bundle-example/env.development demos/client-bundle-example/.env.test
cp dev/scripts/env.test .env.test
cp dev/scripts/env.test dev/scripts/.env.test
cp dev/scripts/env.test packages/cli/.env.test
Expand Down
2 changes: 1 addition & 1 deletion demos/client-bundle-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ docker compose --file ./docker/docker-compose.development.yml up -d && \
npm i && \
npm run build:all && \
npm run setup:all && \
NODE_ENV=production npm -w @prosopo/procaptcha-bundle run bundle && \
NODE_ENV=development npm -w @prosopo/procaptcha-bundle run bundle && \
npm run start:all
```

Expand Down
2 changes: 2 additions & 0 deletions demos/client-bundle-example/env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PROSOPO_SITE_KEY=5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw
PROSOPO_SERVER_URL=http://localhost:9228
4 changes: 3 additions & 1 deletion demos/client-bundle-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@prosopo/client-bundle-example",
"main": "index.js",
"type": "module",
"engines": {
"node": ">=20",
"npm": ">=9"
Expand All @@ -12,8 +13,9 @@
"start": "vite serve ./src --port 9232 --config vite.config.ts",
"clean": "echo 'nothing to clean'"
},
"version": "2.1.3",
"version": "2.1.4",
"devDependencies": {
"@prosopo/dotenv": "2.1.4",
"@types/node": "22.5.5",
"@vitest/coverage-v8": "2.1.1",
"concurrently": "9.0.1",
Expand Down
2 changes: 1 addition & 1 deletion demos/client-bundle-example/src/frictionless.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Get the Element using elementId
const captchaContainer = document.getElementById('procaptcha-container')
render(captchaContainer, {
siteKey: '5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw',
siteKey: import.meta.env.PROSOPO_SITE_KEY,
theme: 'dark',
callback: onCaptchaVerified,
captchaType: 'frictionless',
Expand Down
209 changes: 162 additions & 47 deletions demos/client-bundle-example/src/index.html
Original file line number Diff line number Diff line change
@@ -1,53 +1,168 @@
<!doctype html>
<html lang="en">
<head>
<link href="//cdn.muicss.com/mui-0.10.3/css/mui.min.css" rel="stylesheet" type="text/css" />
<title>Procaptcha demo: Simple page</title>
<script id="procaptchaScript" type="module" src="./assets/procaptcha.bundle.js" async defer></script>
</head>
<body>
<div class="mui-container">
<form action="?" class="mui-form">
<legend>Login</legend>
<div class="mui-textfield mui-textfield--float-label">
<label>Email Address</label>
<input type="email" required />
</div>
<div class="mui-textfield mui-textfield--float-label">
<label>Password</label>
<input type="password" required />
</div>
<div class="mui-textfield mui-textfield--float-label">
<div id="procaptcha-container"></div>
</div>
<div class="mui-textfield mui-textfield--float-label">
<!-- Dev sitekey -->
<div
class="procaptcha"
data-theme="light"
data-sitekey="5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
></div>
</div>
<input type="submit" class="mui-btn mui-btn--raised" />
</form>
</div>
<script type="module">
// Pattern to avoid race condition between Procaptcha script loading and Procaptcha render function call
import { render } from './assets/procaptcha.bundle.js'
<head>
<link href="https://cdn.muicss.com/mui-0.10.3/css/mui.min.css" rel="stylesheet" type="text/css"/>
<title>Procaptcha demo: Simple page</title>
<script id="procaptchaScript" type="module" src="./assets/procaptcha.bundle.js" async defer></script>
<script type="text/javascript">
window.onCaptchaFailed = function () {
console.log('The user failed the captcha')
}
</script>
<script type="module">
window.addEventListener('load', () => {

window.setIsError = (isError) => {
const messageContainer = document.getElementById('messageContainer');
messageContainer.style.color = isError ? 'red' : 'black';
messageContainer.style.display = 'block';
};

window.setMessage = (message) => {
document.getElementById('message').innerText = message;
};

window.onLoggedIn = (token) => {
const url = new URL("/private", config.serverUrl).href;
console.log("getting private resource with token ", token, "at", url);
fetch(url, {
method: "GET",
headers: {
Origin: "http://localhost:9232", // TODO: change this to env var
"Content-Type": "application/json",
Authorization: `Bearer ${token}`,
},
})
.then(async (res) => {
try {
const jsonRes = await res.json();
if (res.status === 200) {
setMessage(jsonRes.message);
}
} catch (err) {
console.log(err);
}
})
.catch((err) => {
console.log(err);
});
};

window.onActionHandler = () => {

const procaptchaElements = document.getElementsByName('procaptcha-response');

if (!procaptchaElements.length) {
alert("Must complete captcha");
return
}

const procaptchaToken = procaptchaElements[0].value;

// Define a callback function to be called when the CAPTCHA is verified
function onCaptchaVerified(output) {
console.log('Captcha verified, output: ' + JSON.stringify(output))
const payload = {
email: document.getElementById('email').value,
name: document.getElementById('name').value,
password: document.getElementById('password').value,
"procaptcha-response": procaptchaToken,
};
const url = new URL('signup', import.meta.env.PROSOPO_SERVER_URL).href;
console.log("posting to", url, "with payload", payload);
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
contentType: "application/json",
}).then((response) => {
return new Promise((resolve) => response.json()
.then((json) => resolve({
status: response.status,
ok: response.ok,
json,
})))
})
.then(async ({status, json, ok}) => {
console.log("status", status, "json", json.message, "ok", ok);
console.log("json", json)
try {
if (status !== 200) {
setIsError(true);
setMessage(json.message);
} else {
setIsError(false);
setMessage(json.message);
}
} catch (err) {
console.log(err);
}
})
.catch((err) => {
console.log(err);
setIsError(true);
setMessage("Error: " + err);
});
};
console.log("here")
}
)
;
</script>

</head>
<body>

<div class="mui-container">
<form action="%PROSOPO_SERVER_URL%/signup" method="POST" class="mui-form">
<h1>Example Login Form</h1>
<div class="mui-textfield mui-textfield--float-label">
<label for="name">Name</label>
<input id="name" type="text" name="name" required/>
</div>
<div class="mui-textfield mui-textfield--float-label">
<label for="email">Email Address</label>
<input id="email" type="email" name="email" required/>
</div>
<div class="mui-textfield mui-textfield--float-label">
<label for="password">Password</label>
<input id="password" type="password" name="password" required/>
</div>
<div class="mui-textfield mui-textfield--float-label">
<div id="procaptcha-container"></div>
</div>
<div class="mui-textfield mui-textfield--float-label">
<!-- Dev sitekey -->
<div
class="procaptcha"
data-theme="light"
data-sitekey="%PROSOPO_SITE_KEY%"
data-failed-callback="onCaptchaFailed"
></div>
</div>
<div id="messageContainer" style="display: none; color: black;"><span id="message"></span></div>
<button type="button" class="mui-btn mui-btn--raised" onclick="onActionHandler()">Submit</button>
</form>
</div>
<script type="module">
// Pattern to avoid race condition between Procaptcha script loading and Procaptcha render function call
import {render} from './assets/procaptcha.bundle.js'

// Define a callback function to be called when the CAPTCHA is verified
function onCaptchaVerified(output) {
console.log('Captcha verified, output: ' + JSON.stringify(output))
}

// Get the Element using elementId
const captchaContainer = document.getElementById('procaptcha-container')
// Render the CAPTCHA explicitly on a container with id "procaptcha-container"
render(captchaContainer, {
siteKey: '5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw',
theme: 'dark',
callback: onCaptchaVerified,
})
</script>
</body>
// Get the Element using elementId
const captchaContainer = document.getElementById('procaptcha-container')
// Render the CAPTCHA explicitly on a container with id "procaptcha-container"
render(captchaContainer, {
siteKey: import.meta.env.PROSOPO_SITE_KEY,
theme: 'dark',
callback: onCaptchaVerified,
"failed-callback": function () {
console.log('The user failed the captcha')
}
})
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion demos/client-bundle-example/src/jsBundleTest.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div
class="procaptcha"
data-theme="light"
data-sitekey="5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw"
data-sitekey="%PROSOPO_SITE_KEY%"
></div>
</form>
</body>
Expand Down
2 changes: 1 addition & 1 deletion demos/client-bundle-example/src/urlParams.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Get the Element using elementId
const captchaContainer = document.getElementById('procaptcha-container')
render(captchaContainer, {
siteKey: '5HGjWAeFDfFCWPsjFQdVV2Msvz2XtMktvgocEZcCj68kUMaw',
siteKey: import.meta.env.PROSOPO_SITE_KEY,
theme: 'dark',
callback: onCaptchaVerified,
})
Expand Down
6 changes: 5 additions & 1 deletion demos/client-bundle-example/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
"sourceMap": false
},
"include": ["**/*.ts"],
"references": []
"references": [
{
"path": "../../packages/dotenv"
}
]
}
32 changes: 23 additions & 9 deletions demos/client-bundle-example/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,26 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
export default {
watch: false,
mode: "development",
server: {
https: false,
host: true,
cors: true,
},
};

import { loadEnv } from "@prosopo/dotenv";
import { type UserConfig, defineConfig } from "vite";

export default defineConfig(({ command, mode }) => {
loadEnv();
return {
watch: false,
mode: "development",
server: {
host: true,
cors: true,
},
define: {
"import.meta.env.PROSOPO_SITE_KEY": JSON.stringify(
process.env.PROSOPO_SITE_KEY,
),
"import.meta.env.PROSOPO_SERVER_URL": JSON.stringify(
process.env.PROSOPO_SERVER_URL,
),
},
} as UserConfig;
});
16 changes: 8 additions & 8 deletions demos/client-example-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prosopo/client-example-server",
"version": "2.1.3",
"version": "2.1.4",
"description": "Backend for client-example",
"main": "dist/app.js",
"type": "module",
Expand Down Expand Up @@ -32,12 +32,12 @@
"@noble/hashes": "1.5.0",
"@polkadot/util": "12.6.2",
"@polkadot/util-crypto": "12.6.2",
"@prosopo/common": "2.1.3",
"@prosopo/contract": "2.1.3",
"@prosopo/dotenv": "2.1.3",
"@prosopo/server": "2.1.3",
"@prosopo/types": "2.1.3",
"@prosopo/util": "2.1.3",
"@prosopo/common": "2.1.4",
"@prosopo/contract": "2.1.4",
"@prosopo/dotenv": "2.1.4",
"@prosopo/server": "2.1.4",
"@prosopo/types": "2.1.4",
"@prosopo/util": "2.1.4",
"@typegoose/auto-increment": "4.6.0",
"cors": "2.8.5",
"express": "4.21.0",
Expand All @@ -47,7 +47,7 @@
"zod": "3.23.8"
},
"devDependencies": {
"@prosopo/config": "2.1.3",
"@prosopo/config": "2.1.4",
"@types/jsonwebtoken": "9.0.6",
"@vitest/coverage-v8": "2.1.1",
"concurrently": "9.0.1",
Expand Down
Loading

0 comments on commit 8f50b6d

Please sign in to comment.