development of SDK while testing with 3rd party app

feat/orm-diffs
Niko PLP 4 hours ago
parent fa87233fc9
commit d23759bb1c
  1. 1
      Cargo.lock
  2. 3
      Cargo.toml
  3. 1
      engine/broker/Cargo.toml
  4. 1
      engine/broker/auth/index.html
  5. 1
      engine/broker/auth/package.json
  6. 6
      engine/broker/auth/src/App.svelte
  7. 4
      engine/broker/auth/src/routes/Home.svelte
  8. 2
      engine/broker/auth/vite.config.js
  9. 31
      engine/broker/src/server_ws.rs
  10. 2
      infra/ngnet/Cargo.toml
  11. 19
      infra/ngnet/README.md
  12. 9
      infra/ngnet/auth/src/main.ts
  13. 2
      infra/ngnet/bootstrap/src/App.svelte
  14. 4
      infra/ngnet/redir/src/lib/Home.svelte
  15. 18
      infra/ngnet/src/main.rs
  16. 3
      package.json
  17. 2
      sdk/js/lib-wasm/Cargo.toml
  18. 42
      sdk/js/lib-wasm/DEV.md
  19. 1
      sdk/js/web/package.json
  20. 6
      sdk/js/web/src/index.ts

1
Cargo.lock generated

@ -3691,6 +3691,7 @@ dependencies = [
"ng-storage-rocksdb",
"ng-verifier",
"once_cell",
"reqwest 0.11.27",
"rust-embed",
"serde",
"serde_bare",

@ -77,4 +77,5 @@ opt-level = 2
[workspace.metadata.scripts]
libwasm = "cd sdk/js/lib-wasm && cargo run-script app && cd ../../.."
libwasm = "cd sdk/js/lib-wasm && cargo run-script app && cd ../../.."
libwasmdev = "cd sdk/js/lib-wasm && cargo run-script appdev && cd ../../.."

@ -26,6 +26,7 @@ async-trait = "0.1.64"
rust-embed = { version = "6.7.0", features = ["include-exclude","debug-embed"] }
urlencoding = "2.1.3"
blake3 = "1.3.1"
reqwest = { version = "0.11.18", features = ["blocking", "native-tls-vendored"] }
ng-async-tungstenite = { version = "0.22.2", git = "https://git.nextgraph.org/NextGraph/async-tungstenite.git", branch = "nextgraph", features = [
"async-std-runtime",
] }

@ -11,6 +11,7 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="http://localhost:14401" />
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>NextGraph Auth</title>

@ -6,6 +6,7 @@
"scripts": {
"dev": "vite",
"build": "vite build --base=./ && node prepare-app-file.cjs && shx rm -rf ./dist/assets",
"dev3": "cross-env NG_DEV3=1 vite",
"builddev": "cross-env NG_DEV=1 vite build --base=./ && shx rm -rf ./dist/assets && shx mkdir -p ../../../app/nextgraph/public_dev && cp ./dist/index.html ../../../app/nextgraph/public_dev/appauth.html",
"preview": "vite preview"
},

@ -90,11 +90,11 @@
// wallets.set(walls);
// };
const redirect_server = import.meta.env.NG_REDIR_SERVER || "nextgraph.net";
const iframe_config = import.meta.env.DEV ? {src:"http://localhost:14404/?o=", origin: "http://localhost:14404"} :
const iframe_config =
import.meta.env.NG_DEV3 ? {src:"http://127.0.0.1:3033/auth/?o=", origin: "http://127.0.0.1:3033"} :
import.meta.env.DEV ? {src:"http://localhost:14404/?o=", origin: "http://localhost:14404"} :
import.meta.env.NG_DEV ? {src:"http://localhost:1421/auth.html?o=", origin: "http://localhost:1421"} :
{src:`https://${redirect_server}/auth/?o=`, origin: `https://${redirect_server}`} ;
// to test ngnet
//const iframe_config = {src:"http://127.0.0.1:3033/auth/?o=", origin: "http://127.0.0.1:3033"};
onMount(async () => {

@ -25,6 +25,7 @@
derived,
cannot_load_offline,
} from "@ng-org/ui-common/store";
import { origin } from "../store";
let display_login_create = !$has_wallets || !$active_wallet;
let unsubscribe;
@ -40,6 +41,9 @@
push("#/wallet/login");
}
});
if (import.meta.env.NG_DEV3 && $origin) {
push("#/?o="+encodeURIComponent($origin));
}
});
onDestroy(() => {

@ -23,7 +23,7 @@ const jsToBottom = () => {
export default defineConfig({
envPrefix: ["VITE_", "NG_"],
server: {
port: 14401
port: 14401,
},
worker: {
format: 'es',

@ -13,6 +13,7 @@
use std::collections::HashMap;
use std::collections::HashSet;
use std::io::Read;
use std::net::IpAddr;
use std::net::SocketAddr;
use std::path::PathBuf;
@ -245,6 +246,7 @@ fn upgrade_ws_or_serve_app(
}
if serve_app && (remote.is_private() || remote.is_loopback()) {
log_debug!("GET {}", uri.path_and_query().unwrap().as_str());
if uri == "/" {
log_debug!("Serving the app");
let sha_file = App::get("index.sha256").unwrap();
@ -272,8 +274,7 @@ fn upgrade_ws_or_serve_app(
.body(Some(file.data.to_vec()))
.unwrap();
return Err(res);
} else if uri.path() == "/auth/" {
log_debug!("Serving auth app");
} else if std::env::var("NG_DEV3").is_ok() && uri.path().starts_with("/auth") {
// if referer.is_none() || referer.unwrap().to_str().is_err() || referer.unwrap().to_str().unwrap() != "https://nextgraph.net/" {
// return Err(make_error(StatusCode::FORBIDDEN));
// }
@ -290,6 +291,32 @@ fn upgrade_ws_or_serve_app(
// }
// None => return Err(make_error(StatusCode::BAD_REQUEST)),
// };
let path = format!(
"http://localhost:14401{}",
uri.path_and_query()
.unwrap()
.as_str()
.get(5..)
.unwrap_or("")
);
log_debug!("SERVING AUTH APP from {path}");
match reqwest::blocking::get(path) {
Err(e) => return Err(make_error(StatusCode::NOT_FOUND)),
Ok(mut res) => {
use std::io::{Cursor, Write};
let mut builder = Response::builder().status(res.status());
for (name, value) in res.headers().into_iter() {
builder = builder.header(name, value);
}
let mut buffer: Vec<u8> = vec![];
let mut cursor = Cursor::new(&mut buffer);
res.copy_to(&mut cursor);
return Err(builder.body(Some(buffer)).unwrap());
}
}
} else if uri == "/auth/" {
log_debug!("Serving auth app");
let sha_file = AppAuth::get("index.sha256").unwrap();
let sha = format!(
"\"{}\"",

@ -15,6 +15,8 @@ rust-version.workspace = true
[package.metadata.scripts]
buildfront = "pnpm -C ./web build && pnpm -C ./bootstrap build && pnpm -C ./auth build && pnpm -C ./redir build"
buildfrontdev = "pnpm -C ./auth builddev && pnpm -C ./bootstrap builddev && pnpm -C ./redir builddev && pnpm -C ./web build"
buildfrontdev3 = "pnpm -C ./auth build && pnpm -C ./web build && pnpm -C ./bootstrap builddev && pnpm -C ./redir build"
[dependencies]
serde = { version = "1.0.142", features = ["derive"] }

@ -11,27 +11,28 @@ npm install -g pnpm
pnpm install
```
## Dev
## Dev (of the app)
compile the 3 front-ends, in dev mode
compile the 4 front-ends, in dev mode
```
pnpm -C ./auth builddev
pnpm -C ./bootstrap builddev
pnpm -C ./redir builddev
cargo run-script buildfrontdev
```
```bash
cd web
pnpm run dev --host
# In another terminal... in the folder ngnet
cargo watch -c -w src -x run
```
> Currently, the ngnet server api is listening on http://127.0.0.1:3033 only, which might cause you trouble with Android emulator (hardcoded in `main.rs`).
> If you need to test from a (virtual) android device, you can use adb to tunnel the connection like: [`adb reverse tcp:3033 tcp:3033`](https://justinchips.medium.com/proxying-adb-client-connections-2ab495f774eb).
## Dev (of the SDK)
```
cargo run-script buildfrontdev3
cargo run
```
## Prod
```

@ -9,11 +9,12 @@
const searchParams = new URLSearchParams(window.location.search);
let o = searchParams.get("o");
let parent_origin = (new URL(o)).origin;
let web_origin;
let web_redirect;
let wallet_port;
let web_origin_host;
//let web_origin_host;
let session;
async function rpc( method:string, port: MessagePort, args?: any) : Promise<any> {
@ -25,16 +26,16 @@ async function rpc( method:string, port: MessagePort, args?: any) : Promise<any>
window.addEventListener("message", async (event)=>{
//console.log("ngnet auth got msg from", event.origin, event.data);
const { method, port } = event.data;
if (event.origin === o) {
if (event.origin === parent_origin) {
if (event.data.ready) return;
if ( method === "init" ) {
web_redirect = event.data.manifest.origin;
let url = new URL(web_redirect);
web_origin = url.origin;
web_origin_host = url.host;
//web_origin_host = url.host;
session = event.data.session;
port.onclose = () => {
console.error("BSP parent window closed its port with nextgraph.net");
console.error("BSP parent window closed its port with us, te redirecting server");
};
wallet_port = port;

@ -36,7 +36,7 @@
const bsp_list = [
"https://nextgraph.eu",
"https://nextgraph.one",
"https://stage1.nextgraph.eu",
"https://stage1.nextgraph.eu"
];
let channel;

@ -39,8 +39,8 @@
let broker = broker_info[1];
broker_name = broker_info[0];
let url;
if (import.meta.env.DEV && broker.localhost === 1421) {
// dev mode
if ( import.meta.env.DEV && broker.localhost === 1421 ) {
// dev mode
url = "http://localhost:14401/";
} else if (import.meta.env.NG_DEV && broker.localhost === 14400) {
// dev mode

@ -136,13 +136,19 @@ async fn main() -> anyhow::Result<()> {
.map(|reply, p: HashMap<String, String>| match p.get("o") {
Some(obj) => {
let decoded = obj.trim();
if BSP_DETAILS.get(decoded).is_none()
&& decoded != "http://localhost:14400"
&& decoded != "http://localhost:1421"
// if decoded.eq("*")
// || (!decoded.starts_with("http://") && !decoded.starts_with("https://"))
// || decoded.len() < 11
let mut allowed = false;
#[cfg(debug_assertions)]
{
if decoded == "http://localhost:14401" {
allowed = true;
}
}
allowed = allowed
|| BSP_DETAILS.get(decoded).is_some()
|| decoded == "http://localhost:14400"
|| decoded == "http://localhost:1421";
if !allowed {
warp::http::StatusCode::BAD_REQUEST.into_response()
} else {
let reply = warp::reply::with_header(

@ -2,7 +2,8 @@
"name": "ng-org",
"private": true,
"version": "0.1.2",
"scripts": {
"scripts": {
"buildfrontdev3": "cargo run-script libwasmdev && pnpm -C ./sdk/js/web builddev3 && pnpm -C ./engine/broker/auth build",
"buildfront": "cargo run-script libwasm && pnpm -C ./app/nextgraph install && pnpm -C ./app/nextgraph webbuild && pnpm -C ./sdk/js/web build && pnpm -C ./engine/broker/auth install && pnpm -C ./engine/broker/auth build",
"buildfrontdev": "pnpm -C ./engine/broker/auth builddev && pnpm -C ./infra/ngnet/bootstrap builddev && pnpm -C ./infra/ngnet/auth builddev && pnpm -C ./infra/ngnet/redir builddev && pnpm -C ./sdk/js/web builddev"
},

@ -17,7 +17,7 @@ rust-version.workspace = true
wasm-opt = false
[package.metadata.scripts]
appdev = "rm -rf pkg/snippets && wasm-pack build --dev --target bundler && node prepare-web.js"
appdev = "wasm-pack build --dev --target bundler && node prepare-web.js"
app = "rm -rf pkg/snippets && wasm-pack build --target bundler && node prepare-web.js"
nodedev = "rm -rf pkg-node/snippets && wasm-pack build --dev -t nodejs -d pkg-node && node prepare-node.js"
node = "rm -rf pkg-node/snippets && wasm-pack build -t nodejs -d pkg-node && node prepare-node.js"

@ -42,6 +42,48 @@ Or automated testing with headless chrome:
wasm-pack test --chrome --headless
```
## Developing against a third party webapp
in a separate terminal, from the root of the mono-repo :
```
pnpm buildfrontdev3
cd engine/broker/auth
pnpm dev3
```
in a separate terminal, from the root of the mono-repo :
```
cd infra/ngnet
cargo run-script buildfrontdev3
cargo run
```
start your local ngd
```
export NG_DEV3=1; cargo run -r -p ngd -- -vv --save-key -l 14400
// then log in to your account by opening
http://localhost:14400
```
finally, start your local third party webapp you will use to test the WASM SDK
```
// this is up to you. by example :
cd sdk/js/examples/multi-framework-signals
pnpm dev
// then open that app in your browser
```
every time you modify the SDK, re-run (at the root of momo-repo) :
```
cargo run-script libwasmdev
// or in the sdk/js/lib-wasm folder run cargo run-script appdev
```
## Production build
```

@ -31,6 +31,7 @@
"build": "tsc && vite build",
"builddevlocal": "tsc && cross-env NG_DEV=1 vite build",
"builddev": "tsc && cross-env NG_DEV_LOCAL_BROKER=1 vite build",
"builddev3": "tsc && cross-env NG_DEV3=1 vite build",
"preview": "vite preview"
},
"dependencies": {

@ -12,11 +12,11 @@ import { createAsyncProxy } from "async-proxy";
let initialized = false;
const redirect_server = import.meta.env.NG_REDIR_SERVER || "nextgraph.net";
const config = import.meta.env.NG_DEV ? {redirect:"http://localhost:14402/#/?o=", origin: "http://localhost:14404"} :
const config =
import.meta.env.NG_DEV3 ? {redirect:"http://127.0.0.1:3033/redir/#/?o=", origin: "http://127.0.0.1:3033"} :
import.meta.env.NG_DEV ? {redirect:"http://localhost:14402/#/?o=", origin: "http://localhost:14404"} :
import.meta.env.NG_DEV_LOCAL_BROKER ? {redirect:"http://localhost:1421/redir.html#/?o=", origin: "http://localhost:1421"} :
{redirect:`https://${redirect_server}/redir/#/?o=`, origin: `https://${redirect_server}`} ;
// to test ngnet
//const config = {redirect:"http://127.0.0.1:3033/auth/#/?o=", origin: "http://127.0.0.1:3033"};
export const init = async function(callback:Function | null, singleton:boolean, access_requests:any) {
if (!window) throw new Error("init(callback,..) can only be called from a browser's window");

Loading…
Cancel
Save