diff --git a/.dockerignore b/.dockerignore index e888aef..e259130 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ **/common/temp **/common/deploy **/compose +node_modules .git .idea .github @@ -9,5 +10,7 @@ Dockerfile .dockerignore docker-compose* - +common/temp +dist +build !./common/deploy diff --git a/Dockerfile b/Dockerfile index 3009aba..7100e7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,22 @@ # syntax=docker/dockerfile:1 -FROM node:16 +FROM node:16 as fula-pack ENV NODE_ENV=production COPY ./ /opt/fula WORKDIR /opt/fula -RUN npm install -g @microsoft/rush && rush update && rush rebuild --verbose --to @functionland/fula-client-react --to @functionland/box || true +RUN npm install -g @microsoft/rush && rush update && rush rebuild --verbose + +FROM node:16 as examples +ENV NODE_ENV=production +ARG EXAMPLE_PATH + +COPY --from=fula-pack /opt/fula /opt/fula +WORKDIR $EXAMPLE_PATH + +RUN npm install + +CMD npm start diff --git a/apps/box/CHANGELOG.json b/apps/box/CHANGELOG.json index cb9bd79..e645751 100644 --- a/apps/box/CHANGELOG.json +++ b/apps/box/CHANGELOG.json @@ -1,6 +1,41 @@ { "name": "@functionland/box", "entries": [ + { + "version": "0.6.4", + "tag": "@functionland/box_v0.6.4", + "date": "Tue, 10 May 2022 07:15:54 GMT", + "comments": { + "patch": [ + { + "comment": "fix replication propagation" + } + ] + } + }, + { + "version": "0.6.3", + "tag": "@functionland/box_v0.6.3", + "date": "Tue, 10 May 2022 06:52:04 GMT", + "comments": { + "patch": [ + { + "comment": "fix fatal error on box protocol implimention." + } + ], + "dependency": [ + { + "comment": "Updating dependency \"@functionland/file-protocol\" from `~0.3.5` to `~0.3.6`" + }, + { + "comment": "Updating dependency \"@functionland/graph-protocol\" from `~0.2.1` to `~0.2.2`" + }, + { + "comment": "Updating dependency \"async-later\" from `0.1.10` to `0.1.11`" + } + ] + } + }, { "version": "0.6.2", "tag": "@functionland/box_v0.6.2", diff --git a/apps/box/CHANGELOG.md b/apps/box/CHANGELOG.md index a7090dc..f1cba04 100644 --- a/apps/box/CHANGELOG.md +++ b/apps/box/CHANGELOG.md @@ -1,6 +1,20 @@ # Change Log - @functionland/box -This log was last generated on Sun, 24 Apr 2022 09:20:16 GMT and should not be manually modified. +This log was last generated on Tue, 10 May 2022 07:15:54 GMT and should not be manually modified. + +## 0.6.4 +Tue, 10 May 2022 07:15:54 GMT + +### Patches + +- fix replication propagation + +## 0.6.3 +Tue, 10 May 2022 06:52:04 GMT + +### Patches + +- fix fatal error on box protocol implimention. ## 0.6.2 Sun, 24 Apr 2022 09:20:16 GMT diff --git a/apps/box/package.json b/apps/box/package.json index c96c0a8..b40433b 100644 --- a/apps/box/package.json +++ b/apps/box/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/box", - "version": "0.6.2", + "version": "0.6.4", "description": "Reference implementation of box server in Node.js", "main": "dist/index.js", "bin": "./cli.js", @@ -27,10 +27,10 @@ "homepage": "https://github.com/functionland/fula#readme", "dependencies": { "@chainsafe/libp2p-noise": "~5.0.2", - "@functionland/file-protocol": "~0.3.5", - "@functionland/graph-protocol": "~0.2.1", + "@functionland/file-protocol": "~0.3.6", + "@functionland/graph-protocol": "~0.2.2", "@ipld/dag-json": "~8.0.8", - "async-later": "0.1.10", + "async-later": "0.1.11", "graphql": "16.3.0", "graphql-tag": "2.12.6", "graphql-tools": "8.2.0", @@ -63,7 +63,6 @@ "@typescript-eslint/eslint-plugin": "~5.13.0", "@typescript-eslint/parser": "~5.13.0", "@web-std/file": "~3.0.2", - "build-helpers": "~0.0.1", "debug": "~4.3.3", "esbuild": "~0.14.25", "esbuild-runner": "~2.2.1", diff --git a/apps/box/scripts/build.mjs b/apps/box/scripts/build.mjs index 7c08eda..4fe3887 100644 --- a/apps/box/scripts/build.mjs +++ b/apps/box/scripts/build.mjs @@ -1,9 +1,7 @@ import { build } from 'esbuild'; import path from 'path'; import fs from 'fs'; -import {clean} from 'build-helpers' -clean() const packages = JSON.parse( fs.readFileSync(path.resolve('./package.json'), { encoding: 'utf8' }) ); diff --git a/apps/box/src/config.ts b/apps/box/src/config.ts index e1f27ea..7e813f0 100644 --- a/apps/box/src/config.ts +++ b/apps/box/src/config.ts @@ -18,7 +18,7 @@ const getPeerId = async () => { const identity = JSON.parse(fs.readFileSync(LIBP2P_PATH + '/identity.json')); return await peerId.createFromJSON(identity) } else { - let identity = await peerId.create() + const identity = await peerId.create() fs.writeFileSync(LIBP2P_PATH + '/identity.json', JSON.stringify(identity.toJSON())) return identity } @@ -28,6 +28,7 @@ const getNetSecret = ()=> { if(config.get("network.key_path")===""){ return undefined } + console.log("Private Mode Enabled") const key = fs.readFileSync(config.get("network.key_path")) return new Protector(key) } diff --git a/common/config/rush/build-cache.json b/common/config/rush/build-cache.json index 04cdd9c..be28da7 100644 --- a/common/config/rush/build-cache.json +++ b/common/config/rush/build-cache.json @@ -10,7 +10,7 @@ * * See https://rushjs.io/pages/maintainer/build_cache/ for details about this experimental feature. */ - "buildCacheEnabled": false, + "buildCacheEnabled": true, /** * (Required) Choose where project build outputs will be cached. diff --git a/docker-compose.dev.yaml b/docker-compose.dev.yaml index 1448438..65b9dd3 100644 --- a/docker-compose.dev.yaml +++ b/docker-compose.dev.yaml @@ -2,35 +2,38 @@ version: '3.8' services: box: - build: . + build: + context: . + dockerfile: Dockerfile + target: fula-pack working_dir: /opt/fula/apps/box command: rushx start - react-cra: - build: . - working_dir: /opt/fula/examples/react-cra - command: rushx start + + react-gallery: + build: + context: . + dockerfile: Dockerfile + target: examples + args: + EXAMPLE_PATH: /opt/fula/examples/gallery/simple/react-app ports: - 3000:3000 + depends_on: + - box react-todo-app: - build: . - working_dir: /opt/fula/examples/react-todo-app + build: + context: . + dockerfile: Dockerfile + target: examples + args: + EXAMPLE_PATH: /opt/fula/examples/react-todo-app volumes: - ./examples/react-todo-app/src:/opt/fula/examples/react-todo-app/src - command: rushx start environment: PORT: 3001 ports: - 3001:3001 - - react-gallery: - build: . - working_dir: /opt/fula/examples/react-gallery - volumes: - - ./examples/react-gallery/src:/opt/fula/examples/react-gallery/src - command: rushx start - environment: - PORT: 3002 - ports: - - 3002:3002 + depends_on: + - box diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index f78ec92..0000000 --- a/examples/.gitignore +++ /dev/null @@ -1 +0,0 @@ -.parcel-cache diff --git a/examples/doc-sync/fuludocs/package.json b/examples/doc-sync/fuludocs/package.json index f82e2fa..9d35ee2 100644 --- a/examples/doc-sync/fuludocs/package.json +++ b/examples/doc-sync/fuludocs/package.json @@ -16,17 +16,17 @@ "license": "ISC", "devDependencies": { "parcel": "^2.4.1", + "parcel-resolver-ignore": "^2.0.0", "process": "^0.11.10", "punycode": "^2.1.1" }, "dependencies": { - "@functionland/fula": "0.6.3", + "@functionland/fula": "../../../libraries/fula-client", "markdown-it": "^12.3.2", "react": "^18.0.0", "react-dom": "^18.0.0", "react-icons": "^4.3.1", "react-router": "^6.3.0", - "react-router-dom": "^6.3.0", - "wrtc": "^0.4.7" + "react-router-dom": "^6.3.0" } } diff --git a/examples/gallery/README.md b/examples/gallery/README.md new file mode 100644 index 0000000..336f1b5 --- /dev/null +++ b/examples/gallery/README.md @@ -0,0 +1,16 @@ +# Gallery +Galley is our example on how to use Fula for creating dApp. +Gallery has to part: +- react-app a simple gallery with upload feature. +- nodejs uploader for uploading some cool image of our Elephant to gallery. +## Simple +- How connect to Boxes +- How to upload/download Photos using File-API. +- How to use graphql to Store and Retrieve `JSON`. +## Private +- How to use pnet in react app and nodejs +## Fula-sec +- How to use fula DIDs +- How to encrypt and store Images. +- How to load and decrypt Images + diff --git a/examples/react-gallery/scripts/photos/Aaron.png b/examples/gallery/assets/Aaron.png similarity index 100% rename from examples/react-gallery/scripts/photos/Aaron.png rename to examples/gallery/assets/Aaron.png diff --git a/examples/react-gallery/scripts/photos/FARHOUD.png b/examples/gallery/assets/FARHOUD.png similarity index 100% rename from examples/react-gallery/scripts/photos/FARHOUD.png rename to examples/gallery/assets/FARHOUD.png diff --git a/examples/react-gallery/scripts/photos/KEYVAN.png b/examples/gallery/assets/KEYVAN.png similarity index 100% rename from examples/react-gallery/scripts/photos/KEYVAN.png rename to examples/gallery/assets/KEYVAN.png diff --git a/examples/react-gallery/scripts/photos/MEHDI 2.png b/examples/gallery/assets/MEHDI 2.png similarity index 100% rename from examples/react-gallery/scripts/photos/MEHDI 2.png rename to examples/gallery/assets/MEHDI 2.png diff --git a/examples/react-gallery/scripts/photos/MEHDI.png b/examples/gallery/assets/MEHDI.png similarity index 100% rename from examples/react-gallery/scripts/photos/MEHDI.png rename to examples/gallery/assets/MEHDI.png diff --git a/examples/react-gallery/scripts/photos/SHEIDA.png b/examples/gallery/assets/SHEIDA.png similarity index 100% rename from examples/react-gallery/scripts/photos/SHEIDA.png rename to examples/gallery/assets/SHEIDA.png diff --git a/examples/react-gallery/.gitignore b/examples/gallery/fula-sec/react-app/.gitignore similarity index 100% rename from examples/react-gallery/.gitignore rename to examples/gallery/fula-sec/react-app/.gitignore diff --git a/examples/gallery/fula-sec/react-app/README.md b/examples/gallery/fula-sec/react-app/README.md new file mode 100644 index 0000000..0c4680a --- /dev/null +++ b/examples/gallery/fula-sec/react-app/README.md @@ -0,0 +1,24 @@ +# Gallery in react + +It's a React web app that you can play with and learn: +- How Use @functionland/fula-sec, for create and importing DIDs. +- How to encrypt data and store it in Box with DID. +- How to retrieve data and decrypt it in Client with DID. + +## Installation +Clone the repository and change to project directory +```bash +cd ./examples/gallery/fula-sec/react-app +npm install +``` + +## Usage + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + diff --git a/examples/react-gallery/package.json b/examples/gallery/fula-sec/react-app/package.json similarity index 96% rename from examples/react-gallery/package.json rename to examples/gallery/fula-sec/react-app/package.json index 6c1a290..1e706f9 100644 --- a/examples/react-gallery/package.json +++ b/examples/gallery/fula-sec/react-app/package.json @@ -11,7 +11,7 @@ "react-scripts": "5.0.1", "react-icons": "^4.3.1", "web-vitals": "^2.1.4", - "@functionland/fula-sec":"^1.0.0", + "@functionland/fula-sec":"^0.6.3", "@functionland/fula": "~0.6.4" }, "devDependencies": { diff --git a/examples/react-gallery/public/favicon.ico b/examples/gallery/fula-sec/react-app/public/favicon.ico similarity index 100% rename from examples/react-gallery/public/favicon.ico rename to examples/gallery/fula-sec/react-app/public/favicon.ico diff --git a/examples/react-gallery/public/index.html b/examples/gallery/fula-sec/react-app/public/index.html similarity index 100% rename from examples/react-gallery/public/index.html rename to examples/gallery/fula-sec/react-app/public/index.html diff --git a/examples/react-gallery/public/logo192.png b/examples/gallery/fula-sec/react-app/public/logo192.png similarity index 100% rename from examples/react-gallery/public/logo192.png rename to examples/gallery/fula-sec/react-app/public/logo192.png diff --git a/examples/react-gallery/public/logo512.png b/examples/gallery/fula-sec/react-app/public/logo512.png similarity index 100% rename from examples/react-gallery/public/logo512.png rename to examples/gallery/fula-sec/react-app/public/logo512.png diff --git a/examples/react-gallery/public/manifest.json b/examples/gallery/fula-sec/react-app/public/manifest.json similarity index 100% rename from examples/react-gallery/public/manifest.json rename to examples/gallery/fula-sec/react-app/public/manifest.json diff --git a/examples/react-gallery/public/robots.txt b/examples/gallery/fula-sec/react-app/public/robots.txt similarity index 100% rename from examples/react-gallery/public/robots.txt rename to examples/gallery/fula-sec/react-app/public/robots.txt diff --git a/examples/react-gallery/src/App.css b/examples/gallery/fula-sec/react-app/src/App.css similarity index 100% rename from examples/react-gallery/src/App.css rename to examples/gallery/fula-sec/react-app/src/App.css diff --git a/examples/react-gallery/src/App.js b/examples/gallery/fula-sec/react-app/src/App.js similarity index 95% rename from examples/react-gallery/src/App.js rename to examples/gallery/fula-sec/react-app/src/App.js index fd18c46..f98aade 100644 --- a/examples/react-gallery/src/App.js +++ b/examples/gallery/fula-sec/react-app/src/App.js @@ -31,11 +31,6 @@ function App() { // User DID const [userDID, setDidObj] = useState(null); - // const createDID = async () => { - // const DID = new FulaDID(); - // const didObj = await DID.create(); - // console.log('didObj', didObj); - // }; useEffect(() => { if (page === pages.GALLERY && status === Status.Online && fula) { @@ -78,7 +73,7 @@ function App() { } })(); } - }, [page, status, fula, userDID.did]); + }, [page, status, fula, userDID?.did]); const onSet = (peers, key_file) => { if (peers.length > 0) { @@ -149,7 +144,7 @@ function App() { return <>
- + {(() => { switch (page) { case pages.CONFIG: diff --git a/examples/react-gallery/src/App.test.js b/examples/gallery/fula-sec/react-app/src/App.test.js similarity index 100% rename from examples/react-gallery/src/App.test.js rename to examples/gallery/fula-sec/react-app/src/App.test.js diff --git a/examples/react-gallery/src/Store.js b/examples/gallery/fula-sec/react-app/src/Store.js similarity index 100% rename from examples/react-gallery/src/Store.js rename to examples/gallery/fula-sec/react-app/src/Store.js diff --git a/examples/react-gallery/src/components/BoxConfig.jsx b/examples/gallery/fula-sec/react-app/src/components/BoxConfig.jsx similarity index 100% rename from examples/react-gallery/src/components/BoxConfig.jsx rename to examples/gallery/fula-sec/react-app/src/components/BoxConfig.jsx diff --git a/examples/react-gallery/src/components/ConnInfo.jsx b/examples/gallery/fula-sec/react-app/src/components/ConnInfo.jsx similarity index 100% rename from examples/react-gallery/src/components/ConnInfo.jsx rename to examples/gallery/fula-sec/react-app/src/components/ConnInfo.jsx diff --git a/examples/react-gallery/src/components/Gallery.jsx b/examples/gallery/fula-sec/react-app/src/components/Gallery.jsx similarity index 100% rename from examples/react-gallery/src/components/Gallery.jsx rename to examples/gallery/fula-sec/react-app/src/components/Gallery.jsx diff --git a/examples/react-gallery/src/components/Identity.jsx b/examples/gallery/fula-sec/react-app/src/components/Identity.jsx similarity index 94% rename from examples/react-gallery/src/components/Identity.jsx rename to examples/gallery/fula-sec/react-app/src/components/Identity.jsx index b5c248c..ec029c1 100644 --- a/examples/react-gallery/src/components/Identity.jsx +++ b/examples/gallery/fula-sec/react-app/src/components/Identity.jsx @@ -1,14 +1,8 @@ import React, { useState } from 'react'; -// import { Status } from '@functionland/fula'; import { FulaDID } from '@functionland/fula-sec'; -// import { -// IoCloudOfflineSharp, -// IoCloudSharp, -// IoBanSharp, -// IoSettingsSharp -// } from 'react-icons/io5'; -export const Identity = ({ status, onSetting, info }) => { + +export const Identity = ({onDIDSet}) => { const [mode, setMode] = useState('None'); const [mnemonicText, setMnemonicText] = useState(''); const [importType, setImportType] = useState('Mnemonic'); @@ -23,7 +17,7 @@ export const Identity = ({ status, onSetting, info }) => { didObj = await DID.importPrivateKey(mnemonicText); } setDidObj(didObj); - onSetting(DID) + onDIDSet(DID) } catch (error) { alert(error); } diff --git a/examples/react-gallery/src/components/Photo.jsx b/examples/gallery/fula-sec/react-app/src/components/Photo.jsx similarity index 100% rename from examples/react-gallery/src/components/Photo.jsx rename to examples/gallery/fula-sec/react-app/src/components/Photo.jsx diff --git a/examples/react-gallery/src/components/Uploader.jsx b/examples/gallery/fula-sec/react-app/src/components/Uploader.jsx similarity index 100% rename from examples/react-gallery/src/components/Uploader.jsx rename to examples/gallery/fula-sec/react-app/src/components/Uploader.jsx diff --git a/examples/react-gallery/src/index.css b/examples/gallery/fula-sec/react-app/src/index.css similarity index 100% rename from examples/react-gallery/src/index.css rename to examples/gallery/fula-sec/react-app/src/index.css diff --git a/examples/react-gallery/src/index.js b/examples/gallery/fula-sec/react-app/src/index.js similarity index 100% rename from examples/react-gallery/src/index.js rename to examples/gallery/fula-sec/react-app/src/index.js diff --git a/examples/react-gallery/src/logo.svg b/examples/gallery/fula-sec/react-app/src/logo.svg similarity index 100% rename from examples/react-gallery/src/logo.svg rename to examples/gallery/fula-sec/react-app/src/logo.svg diff --git a/examples/react-gallery/src/reportWebVitals.js b/examples/gallery/fula-sec/react-app/src/reportWebVitals.js similarity index 100% rename from examples/react-gallery/src/reportWebVitals.js rename to examples/gallery/fula-sec/react-app/src/reportWebVitals.js diff --git a/examples/react-gallery/src/setupTests.js b/examples/gallery/fula-sec/react-app/src/setupTests.js similarity index 100% rename from examples/react-gallery/src/setupTests.js rename to examples/gallery/fula-sec/react-app/src/setupTests.js diff --git a/examples/gallery/fula-sec/uploader/README.md b/examples/gallery/fula-sec/uploader/README.md new file mode 100644 index 0000000..5c5a046 --- /dev/null +++ b/examples/gallery/fula-sec/uploader/README.md @@ -0,0 +1,21 @@ +# uploader + +A command line interface for uploading file image for react-gallery + +Execute the cmd passing in the path to the file you want upload. + +## Install + +``` + > npm install +``` + +## Run + +### Upload all file in folder + +``` + > node index.js -i [folder-path] --boxid [Box ID] -p +./swarm.key -u [Your Mnemonic] +``` + diff --git a/examples/gallery/fula-sec/uploader/index.js b/examples/gallery/fula-sec/uploader/index.js new file mode 100644 index 0000000..757329f --- /dev/null +++ b/examples/gallery/fula-sec/uploader/index.js @@ -0,0 +1,106 @@ +const {createClient} = require("@functionland/fula"); +const {FulaDID,TaggedEncryption} = require("@functionland/fula-sec"); +const fs = require('fs'); +const { File } = require("@web-std/file") +const wrtc = require("wrtc") + + +const argv = require('yargs/yargs')(process.argv.slice(2)) + .usage('Usage: $0 -i [input-file] --boxid [Box ID] -p ./swarm.key') + .option('image-path', { + alias: 'i', + type: 'string', + description: 'Please specify folder path' + }) + .option('boxid', { + alias: 'b', + type: 'string', + description: 'Please specify the Box ID that you would like to connect to.' + }) + .option('identity', { + alias: 'u', + type: 'string', + description: 'Run with your Mnemonic' + }) + .option('swarm-key', { + alias: 'p', + type: 'string', + description: 'Please specify swarm-key' + }) + .demandOption(['i','boxid'], 'Please provide both run and path arguments to work with this tool') + .argv; + +const PHOTOS_PATH= argv.i +const BOX_ID = argv.boxid +const PKEY_PATH = argv.p +const MNEMONIC = argv.u + + +async function main() { + const DID = new FulaDID(); + let didObj; + if (MNEMONIC) { + didObj = await DID.importMnemonic(MNEMONIC) + } else { + didObj = await DID.create(); + } + let fula; + if(PKEY_PATH){ + const netSecret = fs.readFileSync(PKEY_PATH) + fula = await createClient({wrtc,netSecret}) + }else{ + fula = await createClient({wrtc}) + } + console.log("BoxID:",BOX_ID) + console.log("authDID:",didObj.authDID) + const conn = fula.connect(BOX_ID) + conn.on('connected',async ()=>{ + for await (const file of readFiles(PHOTOS_PATH)) { + await upload(fula, file, DID) + } + console.log("done") + fula.close() + process.exit(); + }) + + +} + + +async function* readFiles(path) { + const fileNames = await fs.promises.readdir(PHOTOS_PATH) + console.log(fileNames) + for (const fileName of fileNames){ + console.log(fileName) + const buffer = await fs.promises.readFile(PHOTOS_PATH + fileName) + yield new File([buffer],'fileName') + } +} + +const upload = async (fula, file, userDID) => { + try { + const {cid, key} = await fula.sendEncryptedFile(file) + const tagged = new TaggedEncryption(userDID.did) + let plaintext = { + symmetricKey: key, + CID: cid + } + let jwe = await tagged.encrypt(plaintext.symmetricKey, plaintext.CID, [userDID.did.id]) + await fula.graphql(createMutation, {values: [{cid, _id: cid, jwe}]}) + } catch (e) { + console.log(e.message) + } +} + +const createMutation = ` + mutation addImage($values:JSON){ + create(input:{ + collection:"gallery", + values: $values + }){ + cid + } + } +`; + +main() diff --git a/examples/gallery/fula-sec/uploader/package.json b/examples/gallery/fula-sec/uploader/package.json new file mode 100644 index 0000000..d74490a --- /dev/null +++ b/examples/gallery/fula-sec/uploader/package.json @@ -0,0 +1,16 @@ +{ + "name": "gallery-uploader", + "version": "0.1.0", + "private": true, + "main": "index.js", + "dependencies": { + "@web-std/file": "~3.0.2", + "wrtc": "~0.4.7", + "@functionland/fula": "~0.6.5", + "@functionland/fula-sec":"^0.6.5", + "yargs": "^17.4.0" + }, + "scripts": { + "start": "node index.js" + } +} diff --git a/examples/gallery/private/react-app/.gitignore b/examples/gallery/private/react-app/.gitignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/examples/gallery/private/react-app/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/examples/react-gallery/README.md b/examples/gallery/private/react-app/README.md similarity index 100% rename from examples/react-gallery/README.md rename to examples/gallery/private/react-app/README.md diff --git a/examples/gallery/private/react-app/package.json b/examples/gallery/private/react-app/package.json new file mode 100644 index 0000000..6a7d103 --- /dev/null +++ b/examples/gallery/private/react-app/package.json @@ -0,0 +1,41 @@ +{ + "name": "react-gallery", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^5.16.2", + "@testing-library/react": "^12.1.3", + "@testing-library/user-event": "^13.5.0", + "react": "^17.0.2", + "react-dom": "~17.0.2", + "react-scripts": "5.0.1", + "react-icons": "^4.3.1", + "web-vitals": "^2.1.4", + "@functionland/fula": "../../../../libraries/fula-client" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject", + "init": "node ./scripts/init.js" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/gallery/private/react-app/public/favicon.ico b/examples/gallery/private/react-app/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/examples/gallery/private/react-app/public/favicon.ico differ diff --git a/examples/gallery/private/react-app/public/index.html b/examples/gallery/private/react-app/public/index.html new file mode 100644 index 0000000..aa069f2 --- /dev/null +++ b/examples/gallery/private/react-app/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/examples/gallery/private/react-app/public/logo192.png b/examples/gallery/private/react-app/public/logo192.png new file mode 100644 index 0000000..fc44b0a Binary files /dev/null and b/examples/gallery/private/react-app/public/logo192.png differ diff --git a/examples/gallery/private/react-app/public/logo512.png b/examples/gallery/private/react-app/public/logo512.png new file mode 100644 index 0000000..a4e47a6 Binary files /dev/null and b/examples/gallery/private/react-app/public/logo512.png differ diff --git a/examples/gallery/private/react-app/public/manifest.json b/examples/gallery/private/react-app/public/manifest.json new file mode 100644 index 0000000..080d6c7 --- /dev/null +++ b/examples/gallery/private/react-app/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/examples/gallery/private/react-app/public/robots.txt b/examples/gallery/private/react-app/public/robots.txt new file mode 100644 index 0000000..e9e57dc --- /dev/null +++ b/examples/gallery/private/react-app/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/examples/gallery/private/react-app/src/App.css b/examples/gallery/private/react-app/src/App.css new file mode 100644 index 0000000..6e8c860 --- /dev/null +++ b/examples/gallery/private/react-app/src/App.css @@ -0,0 +1,253 @@ +* { + box-sizing: border-box; + margin: 0; + padding: 0; + font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', + 'Lucida Sans', Arial, sans-serif; +} + +body { + background: linear-gradient( + 90deg, + rgb(71, 5, 109) 0%, + rgba(100, 115, 255, 1) 100% + ); + color: white; +} +.app-header{ + height: 100px; +} +.conn-info{ + /*display: flex;*/ + color: white; + position: absolute; + bottom: 0; + left: 0; + margin: 10px; + position: -webkit-sticky; /* Safari */ + position: sticky; +} +.app { + display: flex; + flex-direction: column; + justify-content: flex-start; + width: 520px; + min-height: 600px; + background: #161a2b; + text-align: center; + margin: 6% auto; + border-radius: 10px; + padding-bottom: 32px; +} + +h1 { + font-size: 24px; +} +h1, h3,h4,h5 { + color: #fff; + margin: 10px; +} + +.complete { + text-decoration: line-through; + opacity: 0.4; +} + +.form { + margin-bottom: 32px; +} + +input[type="text"], textarea { + padding: 14px 32px 14px 16px; + border-radius: 4px 0 0 4px; + border: 2px solid #5d0cff; + outline: none; + width: 320px; + background: transparent; + color: #fff; +} + +input::placeholder { + color: #e2e2e2; +} + +input.edit { + border: 2px solid #149fff; +} + +button { + padding: 16px; + border: none; + border-radius: 0 4px 4px 0; + cursor: pointer; + outline: none; + background: linear-gradient( + 90deg, + rgba(93, 12, 255, 1) 0%, + rgba(155, 0, 250, 1) 100% + ); + color: #fff; + text-transform: capitalize; +} + + + +button.edit { + background: linear-gradient( + 90deg, + rgba(20, 159, 255, 1) 0%, + rgba(17, 122, 255, 1) 100% + ); + padding: 16px 22px; +} +button.single{ + border-radius: 0; + margin: 5px; +} +.container { + margin: auto; + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; +} +.flex-column { + flex-direction: column; +} +.justify-around{ + justify-content: space-around; +} +.row { + display: flex; + justify-content: space-between; + align-items: center; + margin: 4px auto; + color: #fff; + background: linear-gradient( + 90deg, + rgba(255, 118, 20, 1) 0%, + rgba(255, 84, 17, 1) 100% + ); + + padding: 16px; + border-radius: 5px; + width: 90%; +} + +.row:nth-child(4n + 1) { + background: linear-gradient( + 90deg, + rgba(93, 12, 255, 1) 0%, + rgba(155, 0, 250, 1) 100% + ); +} + +.row:nth-child(4n + 2) { + background: linear-gradient( + 90deg, + rgba(255, 12, 241, 1) 0%, + rgba(250, 0, 135, 1) 100% + ); +} + +.row:nth-child(4n + 3) { + background: linear-gradient( + 90deg, + rgba(20, 159, 255, 1) 0%, + rgba(17, 122, 255, 1) 100% + ); +} + +.icons { + display: flex; + align-items: center; + font-size: 24px; + cursor: pointer; +} + +.delete-icon { + margin-right: 5px; + color: #fff; +} + +.edit-icon { + color: #fff; +} +.connect-container{ + margin-top: 100px; +} + + +/* Loading animation */ +.lds-ellipsis { + display: inline-block; + position: relative; + width: 80px; + height: 80px; +} +.lds-ellipsis div { + position: absolute; + top: 33px; + width: 13px; + height: 13px; + border-radius: 50%; + background: #fff; + animation-timing-function: cubic-bezier(0, 1, 1, 0); +} +.lds-ellipsis div:nth-child(1) { + left: 8px; + animation: lds-ellipsis1 0.6s infinite; +} +.lds-ellipsis div:nth-child(2) { + left: 8px; + animation: lds-ellipsis2 0.6s infinite; +} +.lds-ellipsis div:nth-child(3) { + left: 32px; + animation: lds-ellipsis2 0.6s infinite; +} +.lds-ellipsis div:nth-child(4) { + left: 56px; + animation: lds-ellipsis3 0.6s infinite; +} +@keyframes lds-ellipsis1 { + 0% { + transform: scale(0); + } + 100% { + transform: scale(1); + } +} +@keyframes lds-ellipsis3 { + 0% { + transform: scale(1); + } + 100% { + transform: scale(0); + } +} +@keyframes lds-ellipsis2 { + 0% { + transform: translate(0, 0); + } + 100% { + transform: translate(24px, 0); + } +} + +.photo { + width:100%; + padding: 10px; +} + +.identityContainer{ + display:flex; + padding: 10px; + justify-content:space-around; +} +.importMnemonicContainer{ + display:flex; + padding: 10px; + flex-direction: column; + justify-content:space-around; +} \ No newline at end of file diff --git a/examples/gallery/private/react-app/src/App.js b/examples/gallery/private/react-app/src/App.js new file mode 100644 index 0000000..7e65d80 --- /dev/null +++ b/examples/gallery/private/react-app/src/App.js @@ -0,0 +1,151 @@ +import './App.css'; + +import React, {useEffect, useState} from "react"; +import {createClient, Status} from "@functionland/fula"; + +import {ConnInfo} from "./components/ConnInfo"; +import {BoxConfig} from "./components/BoxConfig"; +import {Uploader} from "./components/Uploader"; +import {Gallery} from "./components/Gallery"; + + +const pages = { + GALLERY: 'home', + CONFIG: 'config', +} + +function App() { + // simple routing mechanism page will keep our route state + const [page, setPage] = useState(pages.CONFIG) + // status of connection + const [status, setStatus] = useState(null) + // connection logs + const [connInfo, setConnInfo] = useState("") + // Fula client + const [fula, setFula] = useState(undefined) + // Id of the box + const [boxIds, setBoxIds] = useState([]) + // List of photos to show + const [photos, setPhotos] = useState([]) + + + useEffect(() => { + if (page === pages.GALLERY && status === Status.Online && fula) { + (async () => { + const allData = await fula.graphql(readQuery) + if (allData && allData.data && allData.data.read) { + setPhotos([]) + for (const {cid} of allData.data.read) { + const file = await fula.receiveFile(cid) + setPhotos((prev) => [...prev, file]) + } + } else { + setPhotos([]) + } + })() + } + }, [page, status, fula]) + + const onSet = (peers, key_file) => { + if (peers.length > 0) { + setBoxIds(peers); + setPage(pages.GALLERY); + setStatus(Status.Connecting); + (async () => { + try { + setConnInfo("") + if (fula) + fula.close() + let _fula + if (key_file) { + const key = await key_file.arrayBuffer() + _fula = await createClient({netSecret:key}) + setFula(_fula) + } else { + _fula = await createClient() + setFula(_fula) + } + let con = _fula.connect(peers) + con.on('status', (_status) => { + setStatus(_status) + _status === Status.Online && setConnInfo("") + }) + con.on('error', () => { + setConnInfo("Server not available") + }) + + } catch (e) { + setConnInfo(e.message) + } + })(); + } + + } + + // call back function for uploading a photo + // it will upload the file using fula file api + // and then store its cid in fula data + const onUpload = async (selectedFile) => { + try { + const cid = await fula.sendFile(selectedFile) + await fula.graphql(createMutation, {values: [{cid, _id: cid}]}) + setPhotos((prev) => [selectedFile, ...prev]) + } catch (e) { + console.log(e.message) + } + } + + // call back for routing to setting + const onSetting = () => { + setPage(pages.CONFIG) + } + + return <> +
+ {(() => { + switch (page) { + case pages.CONFIG: + return + case pages.GALLERY: + return <> +

Functionland Sample Gallery

+ {status === Status.Online && } + {status === Status.Online && } + + + default: + return

Route not found

+ } + })()} +
+ + + +} + +export default App; + + +export const readQuery = ` + query { + read(input:{ + collection:"gallery", + filter:{} + }){ + cid + } + } +` + + +export const createMutation = ` + mutation addImage($values:JSON){ + create(input:{ + collection:"gallery", + values: $values + }){ + cid + } + } +`; + diff --git a/examples/gallery/private/react-app/src/App.test.js b/examples/gallery/private/react-app/src/App.test.js new file mode 100644 index 0000000..1f03afe --- /dev/null +++ b/examples/gallery/private/react-app/src/App.test.js @@ -0,0 +1,8 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/examples/gallery/private/react-app/src/components/BoxConfig.jsx b/examples/gallery/private/react-app/src/components/BoxConfig.jsx new file mode 100644 index 0000000..3c788c8 --- /dev/null +++ b/examples/gallery/private/react-app/src/components/BoxConfig.jsx @@ -0,0 +1,59 @@ +import React, {useState, useRef} from 'react'; + +export const BoxConfig = ({serverId, onSet}) => { + + const inputRef = useRef(null); + const [_serverId, _setServerId] = useState(serverId) + const [selectedFile, setSelectedFile] = useState(null) + + const handleSelectFile = (event) => { + console.log(event.target.files[0]) + setSelectedFile(event.target.files[0]) + } + + const _onSet = (e) => { + e.preventDefault(); + onSet(_serverId.split(','), selectedFile) + } + + + return <> +
+
+
+ _setServerId(e.target.value)} + name='text' + ref={inputRef} + /> +
+ +
+
+ + + + +
+ +
+ + + + +} diff --git a/examples/gallery/private/react-app/src/components/ConnInfo.jsx b/examples/gallery/private/react-app/src/components/ConnInfo.jsx new file mode 100644 index 0000000..2d5abee --- /dev/null +++ b/examples/gallery/private/react-app/src/components/ConnInfo.jsx @@ -0,0 +1,36 @@ +import React from 'react'; +import {Status} from '@functionland/fula' +import {IoCloudOfflineSharp, IoCloudSharp, IoBanSharp, IoSettingsSharp} from 'react-icons/io5' + +export const ConnInfo = ({status, onSetting, info}) => { + + const _onSetting = async (e) => { + e.preventDefault(); + onSetting() + } + + return ( +
+ {(() => { + switch (status) { + case Status.Online: + return + case Status.Offline: + return + case Status.Connecting: + return
+
+
+
+
+
+ default: + return + } + })()} + + {info} +
+ ) +} diff --git a/examples/gallery/private/react-app/src/components/Gallery.jsx b/examples/gallery/private/react-app/src/components/Gallery.jsx new file mode 100644 index 0000000..4fb0276 --- /dev/null +++ b/examples/gallery/private/react-app/src/components/Gallery.jsx @@ -0,0 +1,23 @@ +import React from 'react'; +import Photo from './Photo'; + + +export const Gallery = ({ photos }) => { + return ( + <> + { + photos.length > 0 && photos.map((photo, index) => ( +
+ +
+ )) + } + { + photos.length === 0 &&
+

no photo

+
+ } + + ); + +} diff --git a/examples/gallery/private/react-app/src/components/Photo.jsx b/examples/gallery/private/react-app/src/components/Photo.jsx new file mode 100644 index 0000000..c700ecf --- /dev/null +++ b/examples/gallery/private/react-app/src/components/Photo.jsx @@ -0,0 +1,38 @@ +import React, { useState, useEffect } from 'react'; + + +const Photo = ({ photo }) => { + const [content, setContent] = useState(null) + + useEffect(() => { + const fileToDataUrl = async () => { + if (!photo) { + console.log("no photo") + return + } + try { + let reader = new FileReader(); + reader.readAsDataURL(photo); + reader.onloadend = () => setContent(reader.result) + }catch (e) { + console.log(e) + } + + } + if(photo){ + (async () => { + await fileToDataUrl(photo); + })() + } + }, [photo]); + + + + + return
+ {photo.name}/ +
+ +}; + +export default Photo; diff --git a/examples/gallery/private/react-app/src/components/Uploader.jsx b/examples/gallery/private/react-app/src/components/Uploader.jsx new file mode 100644 index 0000000..35cc758 --- /dev/null +++ b/examples/gallery/private/react-app/src/components/Uploader.jsx @@ -0,0 +1,35 @@ +import React, { useState, useRef } from 'react'; + +export const Uploader = ({onUpload})=>{ + + const inputRef = useRef(null); + const [selectedFile, setSelectedFile] = useState(null) + + const handleSelectFile = (event) => { + setSelectedFile(event.target.files[0]) + } + + const _onUpload = async (e) => { + e.preventDefault(); + if(selectedFile) + onUpload(selectedFile) + } + + return
+ + +
+} + + + + diff --git a/examples/gallery/private/react-app/src/index.css b/examples/gallery/private/react-app/src/index.css new file mode 100644 index 0000000..53e06f2 --- /dev/null +++ b/examples/gallery/private/react-app/src/index.css @@ -0,0 +1,14 @@ +body { + color: white; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/examples/gallery/private/react-app/src/index.js b/examples/gallery/private/react-app/src/index.js new file mode 100644 index 0000000..ef2edf8 --- /dev/null +++ b/examples/gallery/private/react-app/src/index.js @@ -0,0 +1,17 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +ReactDOM.render( + + + , + document.getElementById('root') +); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/examples/gallery/private/react-app/src/logo.svg b/examples/gallery/private/react-app/src/logo.svg new file mode 100644 index 0000000..9dfc1c0 --- /dev/null +++ b/examples/gallery/private/react-app/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/gallery/private/react-app/src/reportWebVitals.js b/examples/gallery/private/react-app/src/reportWebVitals.js new file mode 100644 index 0000000..5253d3a --- /dev/null +++ b/examples/gallery/private/react-app/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/examples/gallery/private/react-app/src/setupTests.js b/examples/gallery/private/react-app/src/setupTests.js new file mode 100644 index 0000000..8f2609b --- /dev/null +++ b/examples/gallery/private/react-app/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; diff --git a/examples/gallery/private/uploader/README.md b/examples/gallery/private/uploader/README.md new file mode 100644 index 0000000..4231c98 --- /dev/null +++ b/examples/gallery/private/uploader/README.md @@ -0,0 +1,21 @@ +# uploader + +A command line interface for uploading file image for react-gallery + +Execute the cmd passing in the path to the file you want upload. + +## Install + +``` + > npm install +``` + +## Run + +### Upload all file in folder + +``` + > node index.js -i [folder-path] --boxid [Box ID] -p +./swarm.key +``` + diff --git a/examples/gallery/private/uploader/index.js b/examples/gallery/private/uploader/index.js new file mode 100644 index 0000000..6657026 --- /dev/null +++ b/examples/gallery/private/uploader/index.js @@ -0,0 +1,68 @@ +const {createClient} = require("@functionland/fula"); +const fs=require('fs'); +const { File } = require("@web-std/file") +const wrtc = require("wrtc") + + +const argv = require('yargs/yargs')(process.argv.slice(2)) + .usage('Usage: $0 -i [input-file] --boxid [Box ID] -p ./swarm.key') + .demandOption(['i'], 'Please specify folder path') + .demandOption(['p'], 'Please specify swarm-key') + .demandOption(['boxid'], 'Please specify the Box ID that you would like to connect to.') + .argv; + +const PHOTOS_PATH= argv.i +const BOX_ID = argv.boxid +const PKEY_PATH = argv.p + +const netSecret = fs.readFileSync(PKEY_PATH) + + +async function main() { + const fula = await createClient({wrtc,netSecret}) + console.log("BoxID:",BOX_ID) + const conn = fula.connect(BOX_ID) + conn.on('connected',async ()=>{ + for await (const file of readFiles(PHOTOS_PATH)) { + await upload(fula, file) + } + console.log("done") + fula.close() + process.exit(); + }) + + +} + + +async function* readFiles(path) { + const fileNames = await fs.promises.readdir(PHOTOS_PATH) + console.log(fileNames) + for (const fileName of fileNames){ + console.log(fileName) + const buffer = await fs.promises.readFile(PHOTOS_PATH + fileName) + yield new File([buffer],'fileName') + } +} + +const upload = async (fula, file) => { + try { + const cid = await fula.sendFile(file) + await fula.graphql(createMutation, {values: [{cid, _id: cid}]}) + } catch (e) { + console.log(e.message) + } +} + +const createMutation = ` + mutation addImage($values:JSON){ + create(input:{ + collection:"gallery", + values: $values + }){ + cid + } + } +`; + +main() diff --git a/examples/gallery/private/uploader/package.json b/examples/gallery/private/uploader/package.json new file mode 100644 index 0000000..58478cf --- /dev/null +++ b/examples/gallery/private/uploader/package.json @@ -0,0 +1,15 @@ +{ + "name": "react-gallery-uploader", + "version": "0.1.0", + "private": true, + "main": "index.js", + "dependencies": { + "@web-std/file": "~3.0.2", + "wrtc": "~0.4.7", + "@functionland/fula": "~0.6.5", + "yargs": "^17.4.0" + }, + "scripts": { + "start": "node index.js" + } +} diff --git a/examples/gallery/simple/react-app/.gitignore b/examples/gallery/simple/react-app/.gitignore new file mode 100644 index 0000000..4d29575 --- /dev/null +++ b/examples/gallery/simple/react-app/.gitignore @@ -0,0 +1,23 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* diff --git a/examples/gallery/simple/react-app/README.md b/examples/gallery/simple/react-app/README.md new file mode 100644 index 0000000..df630c8 --- /dev/null +++ b/examples/gallery/simple/react-app/README.md @@ -0,0 +1,28 @@ +# Gallery in react + +It's a react web app that you can play with and learn: +- How connect to Boxes +- How to upload/download Photos using File-API. +- How to use graphql to Store and Retrieve `JSON`. + +## Installation +Clone the repository and change to project directory +```bash +cd ./examples/react-gallery +npm install +``` + +## Usage + +### `BOX_ID="YOUR_BOX_ID" npm run init` +Run's the script for populating BOX with FXland NFTs that local under ./scripts/photos. \ +Note:you most pass boxId as environment variable `BOX_ID="YOUR_BOX_ID"` + +### `npm start` + +Runs the app in the development mode.\ +Open [http://localhost:3000](http://localhost:3000) to view it in your browser. + +The page will reload when you make changes.\ +You may also see any lint errors in the console. + diff --git a/examples/gallery/simple/react-app/package.json b/examples/gallery/simple/react-app/package.json new file mode 100644 index 0000000..6a7d103 --- /dev/null +++ b/examples/gallery/simple/react-app/package.json @@ -0,0 +1,41 @@ +{ + "name": "react-gallery", + "version": "0.1.0", + "private": true, + "dependencies": { + "@testing-library/jest-dom": "^5.16.2", + "@testing-library/react": "^12.1.3", + "@testing-library/user-event": "^13.5.0", + "react": "^17.0.2", + "react-dom": "~17.0.2", + "react-scripts": "5.0.1", + "react-icons": "^4.3.1", + "web-vitals": "^2.1.4", + "@functionland/fula": "../../../../libraries/fula-client" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject", + "init": "node ./scripts/init.js" + }, + "eslintConfig": { + "extends": [ + "react-app", + "react-app/jest" + ] + }, + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/examples/gallery/simple/react-app/public/favicon.ico b/examples/gallery/simple/react-app/public/favicon.ico new file mode 100644 index 0000000..a11777c Binary files /dev/null and b/examples/gallery/simple/react-app/public/favicon.ico differ diff --git a/examples/gallery/simple/react-app/public/index.html b/examples/gallery/simple/react-app/public/index.html new file mode 100644 index 0000000..aa069f2 --- /dev/null +++ b/examples/gallery/simple/react-app/public/index.html @@ -0,0 +1,43 @@ + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/examples/gallery/simple/react-app/public/logo192.png b/examples/gallery/simple/react-app/public/logo192.png new file mode 100644 index 0000000..e69de29 diff --git a/examples/gallery/simple/react-app/public/logo512.png b/examples/gallery/simple/react-app/public/logo512.png new file mode 100644 index 0000000..e69de29 diff --git a/examples/gallery/simple/react-app/public/manifest.json b/examples/gallery/simple/react-app/public/manifest.json new file mode 100644 index 0000000..080d6c7 --- /dev/null +++ b/examples/gallery/simple/react-app/public/manifest.json @@ -0,0 +1,25 @@ +{ + "short_name": "React App", + "name": "Create React App Sample", + "icons": [ + { + "src": "favicon.ico", + "sizes": "64x64 32x32 24x24 16x16", + "type": "image/x-icon" + }, + { + "src": "logo192.png", + "type": "image/png", + "sizes": "192x192" + }, + { + "src": "logo512.png", + "type": "image/png", + "sizes": "512x512" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#000000", + "background_color": "#ffffff" +} diff --git a/examples/gallery/simple/react-app/public/robots.txt b/examples/gallery/simple/react-app/public/robots.txt new file mode 100644 index 0000000..e9e57dc --- /dev/null +++ b/examples/gallery/simple/react-app/public/robots.txt @@ -0,0 +1,3 @@ +# https://www.robotstxt.org/robotstxt.html +User-agent: * +Disallow: diff --git a/examples/gallery/simple/react-app/src/App.css b/examples/gallery/simple/react-app/src/App.css new file mode 100644 index 0000000..6e8c860 --- /dev/null +++ b/examples/gallery/simple/react-app/src/App.css @@ -0,0 +1,253 @@ +* { + box-sizing: border-box; + margin: 0; + padding: 0; + font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', + 'Lucida Sans', Arial, sans-serif; +} + +body { + background: linear-gradient( + 90deg, + rgb(71, 5, 109) 0%, + rgba(100, 115, 255, 1) 100% + ); + color: white; +} +.app-header{ + height: 100px; +} +.conn-info{ + /*display: flex;*/ + color: white; + position: absolute; + bottom: 0; + left: 0; + margin: 10px; + position: -webkit-sticky; /* Safari */ + position: sticky; +} +.app { + display: flex; + flex-direction: column; + justify-content: flex-start; + width: 520px; + min-height: 600px; + background: #161a2b; + text-align: center; + margin: 6% auto; + border-radius: 10px; + padding-bottom: 32px; +} + +h1 { + font-size: 24px; +} +h1, h3,h4,h5 { + color: #fff; + margin: 10px; +} + +.complete { + text-decoration: line-through; + opacity: 0.4; +} + +.form { + margin-bottom: 32px; +} + +input[type="text"], textarea { + padding: 14px 32px 14px 16px; + border-radius: 4px 0 0 4px; + border: 2px solid #5d0cff; + outline: none; + width: 320px; + background: transparent; + color: #fff; +} + +input::placeholder { + color: #e2e2e2; +} + +input.edit { + border: 2px solid #149fff; +} + +button { + padding: 16px; + border: none; + border-radius: 0 4px 4px 0; + cursor: pointer; + outline: none; + background: linear-gradient( + 90deg, + rgba(93, 12, 255, 1) 0%, + rgba(155, 0, 250, 1) 100% + ); + color: #fff; + text-transform: capitalize; +} + + + +button.edit { + background: linear-gradient( + 90deg, + rgba(20, 159, 255, 1) 0%, + rgba(17, 122, 255, 1) 100% + ); + padding: 16px 22px; +} +button.single{ + border-radius: 0; + margin: 5px; +} +.container { + margin: auto; + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; +} +.flex-column { + flex-direction: column; +} +.justify-around{ + justify-content: space-around; +} +.row { + display: flex; + justify-content: space-between; + align-items: center; + margin: 4px auto; + color: #fff; + background: linear-gradient( + 90deg, + rgba(255, 118, 20, 1) 0%, + rgba(255, 84, 17, 1) 100% + ); + + padding: 16px; + border-radius: 5px; + width: 90%; +} + +.row:nth-child(4n + 1) { + background: linear-gradient( + 90deg, + rgba(93, 12, 255, 1) 0%, + rgba(155, 0, 250, 1) 100% + ); +} + +.row:nth-child(4n + 2) { + background: linear-gradient( + 90deg, + rgba(255, 12, 241, 1) 0%, + rgba(250, 0, 135, 1) 100% + ); +} + +.row:nth-child(4n + 3) { + background: linear-gradient( + 90deg, + rgba(20, 159, 255, 1) 0%, + rgba(17, 122, 255, 1) 100% + ); +} + +.icons { + display: flex; + align-items: center; + font-size: 24px; + cursor: pointer; +} + +.delete-icon { + margin-right: 5px; + color: #fff; +} + +.edit-icon { + color: #fff; +} +.connect-container{ + margin-top: 100px; +} + + +/* Loading animation */ +.lds-ellipsis { + display: inline-block; + position: relative; + width: 80px; + height: 80px; +} +.lds-ellipsis div { + position: absolute; + top: 33px; + width: 13px; + height: 13px; + border-radius: 50%; + background: #fff; + animation-timing-function: cubic-bezier(0, 1, 1, 0); +} +.lds-ellipsis div:nth-child(1) { + left: 8px; + animation: lds-ellipsis1 0.6s infinite; +} +.lds-ellipsis div:nth-child(2) { + left: 8px; + animation: lds-ellipsis2 0.6s infinite; +} +.lds-ellipsis div:nth-child(3) { + left: 32px; + animation: lds-ellipsis2 0.6s infinite; +} +.lds-ellipsis div:nth-child(4) { + left: 56px; + animation: lds-ellipsis3 0.6s infinite; +} +@keyframes lds-ellipsis1 { + 0% { + transform: scale(0); + } + 100% { + transform: scale(1); + } +} +@keyframes lds-ellipsis3 { + 0% { + transform: scale(1); + } + 100% { + transform: scale(0); + } +} +@keyframes lds-ellipsis2 { + 0% { + transform: translate(0, 0); + } + 100% { + transform: translate(24px, 0); + } +} + +.photo { + width:100%; + padding: 10px; +} + +.identityContainer{ + display:flex; + padding: 10px; + justify-content:space-around; +} +.importMnemonicContainer{ + display:flex; + padding: 10px; + flex-direction: column; + justify-content:space-around; +} \ No newline at end of file diff --git a/examples/gallery/simple/react-app/src/App.js b/examples/gallery/simple/react-app/src/App.js new file mode 100644 index 0000000..888de68 --- /dev/null +++ b/examples/gallery/simple/react-app/src/App.js @@ -0,0 +1,152 @@ +import './App.css'; + +import React, {useEffect, useState} from "react"; +import {createClient, Status} from "@functionland/fula"; + +import {ConnInfo} from "./components/ConnInfo"; +import {BoxConfig} from "./components/BoxConfig"; +import {Uploader} from "./components/Uploader"; +import {Gallery} from "./components/Gallery"; + + +const pages = { + GALLERY: 'home', + CONFIG: 'config', +} + +function App() { + // simple routing mechanism page will keep our route state + const [page, setPage] = useState(pages.CONFIG) + // status of connection + const [status, setStatus] = useState(null) + // connection logs + const [connInfo, setConnInfo] = useState("") + // Fula client + const [fula, setFula] = useState(undefined) + // Id of the box + const [boxIds, setBoxIds] = useState([]) + // List of photos to show + const [photos, setPhotos] = useState([]) + + + useEffect(() => { + if (page === pages.GALLERY && status === Status.Online && fula) { + (async () => { + const allData = await fula.graphql(readQuery) + if (allData && allData.data && allData.data.read) { + setPhotos([]) + for (const {cid} of allData.data.read) { + const file = await fula.receiveFile(cid) + setPhotos((prev) => [...prev, file]) + } + } else { + setPhotos([]) + } + })() + } + }, [page, status, fula]) + + const onSet = (peers) => { + if (peers.length > 0) { + setPage(pages.GALLERY) + setBoxIds(peers); + (async () => { + try { + setConnInfo("") + if (fula) + fula.close() + let _fula = await createClient() + setFula(_fula) + let con = _fula.connect(peers) + setStatus(Status.Connecting) + con.on('status', (_status) => { + setStatus(_status) + _status === Status.Online && setConnInfo("") + }) + con.on('error', () => { + setConnInfo("Server not available") + }) + } catch (e) { + setConnInfo(e.message) + } + })(); + } + + } + + // call back function for uploading a photo + // it will upload the file using fula file api + // and then store its cid in fula data + const onUpload = async (selectedFile) => { + try { + const cid = await fula.sendFile(selectedFile) + await fula.graphql(createMutation, {values: [{cid, _id: cid}]}) + setPhotos((prev) => [selectedFile, ...prev]) + } catch (e) { + console.log(e.message) + } + } + + // call back for routing to setting + const onSetting = () => { + setPage(pages.CONFIG) + } + + return <> +
+ {(() => { + switch (page) { + case pages.CONFIG: + return + case pages.GALLERY: + return <> +

Functionland Sample Gallery

+ {status === Status.Online && } + {status === Status.Online && } + {status === Status.Connecting &&
+
Connecting
+
+
+
+
+
+
+
+ } + + default: + return

Route not found

+ } + })()} +
+ + + +} + +export default App; + + +export const readQuery = ` + query { + read(input:{ + collection:"gallery", + filter:{} + }){ + cid + } + } +` + + +export const createMutation = ` + mutation addImage($values:JSON){ + create(input:{ + collection:"gallery", + values: $values + }){ + cid + } + } +`; + diff --git a/examples/gallery/simple/react-app/src/App.test.js b/examples/gallery/simple/react-app/src/App.test.js new file mode 100644 index 0000000..1f03afe --- /dev/null +++ b/examples/gallery/simple/react-app/src/App.test.js @@ -0,0 +1,8 @@ +import { render, screen } from '@testing-library/react'; +import App from './App'; + +test('renders learn react link', () => { + render(); + const linkElement = screen.getByText(/learn react/i); + expect(linkElement).toBeInTheDocument(); +}); diff --git a/examples/gallery/simple/react-app/src/components/BoxConfig.jsx b/examples/gallery/simple/react-app/src/components/BoxConfig.jsx new file mode 100644 index 0000000..cb5e144 --- /dev/null +++ b/examples/gallery/simple/react-app/src/components/BoxConfig.jsx @@ -0,0 +1,44 @@ +import React, {useState, useRef} from 'react'; + +export const BoxConfig = ({serverId, onSet}) => { + + const inputRef = useRef(null); + const [_serverId, _setServerId] = useState(serverId) + + const _onSet = (e) => { + e.preventDefault(); + onSet(_serverId.split(',')) + } + + return <> +
+
+
+ _setServerId(e.target.value)} + name='text' + ref={inputRef} + /> +
+ +
+
+ +
+ +
+ + + + +} diff --git a/examples/gallery/simple/react-app/src/components/ConnInfo.jsx b/examples/gallery/simple/react-app/src/components/ConnInfo.jsx new file mode 100644 index 0000000..1ffa371 --- /dev/null +++ b/examples/gallery/simple/react-app/src/components/ConnInfo.jsx @@ -0,0 +1,29 @@ +import React from 'react'; +import {Status} from '@functionland/fula' +import {IoCloudOfflineSharp, IoCloudSharp, IoBanSharp, IoSettingsSharp} from 'react-icons/io5' + +export const ConnInfo = ({status, onSetting, info}) => { + + const _onSetting = async (e) => { + e.preventDefault(); + onSetting() + } + + return ( +
+ {(() => { + switch (status) { + case Status.Online: + return + case Status.Offline: + return + default: + return + } + })()} + + {info} +
+ ) +} diff --git a/examples/gallery/simple/react-app/src/components/Gallery.jsx b/examples/gallery/simple/react-app/src/components/Gallery.jsx new file mode 100644 index 0000000..4fb0276 --- /dev/null +++ b/examples/gallery/simple/react-app/src/components/Gallery.jsx @@ -0,0 +1,23 @@ +import React from 'react'; +import Photo from './Photo'; + + +export const Gallery = ({ photos }) => { + return ( + <> + { + photos.length > 0 && photos.map((photo, index) => ( +
+ +
+ )) + } + { + photos.length === 0 &&
+

no photo

+
+ } + + ); + +} diff --git a/examples/gallery/simple/react-app/src/components/Photo.jsx b/examples/gallery/simple/react-app/src/components/Photo.jsx new file mode 100644 index 0000000..c700ecf --- /dev/null +++ b/examples/gallery/simple/react-app/src/components/Photo.jsx @@ -0,0 +1,38 @@ +import React, { useState, useEffect } from 'react'; + + +const Photo = ({ photo }) => { + const [content, setContent] = useState(null) + + useEffect(() => { + const fileToDataUrl = async () => { + if (!photo) { + console.log("no photo") + return + } + try { + let reader = new FileReader(); + reader.readAsDataURL(photo); + reader.onloadend = () => setContent(reader.result) + }catch (e) { + console.log(e) + } + + } + if(photo){ + (async () => { + await fileToDataUrl(photo); + })() + } + }, [photo]); + + + + + return
+ {photo.name}/ +
+ +}; + +export default Photo; diff --git a/examples/gallery/simple/react-app/src/components/Uploader.jsx b/examples/gallery/simple/react-app/src/components/Uploader.jsx new file mode 100644 index 0000000..35cc758 --- /dev/null +++ b/examples/gallery/simple/react-app/src/components/Uploader.jsx @@ -0,0 +1,35 @@ +import React, { useState, useRef } from 'react'; + +export const Uploader = ({onUpload})=>{ + + const inputRef = useRef(null); + const [selectedFile, setSelectedFile] = useState(null) + + const handleSelectFile = (event) => { + setSelectedFile(event.target.files[0]) + } + + const _onUpload = async (e) => { + e.preventDefault(); + if(selectedFile) + onUpload(selectedFile) + } + + return
+ + +
+} + + + + diff --git a/examples/gallery/simple/react-app/src/index.css b/examples/gallery/simple/react-app/src/index.css new file mode 100644 index 0000000..53e06f2 --- /dev/null +++ b/examples/gallery/simple/react-app/src/index.css @@ -0,0 +1,14 @@ +body { + color: white; + margin: 0; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', + 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', + sans-serif; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +code { + font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', + monospace; +} diff --git a/examples/gallery/simple/react-app/src/index.js b/examples/gallery/simple/react-app/src/index.js new file mode 100644 index 0000000..ef2edf8 --- /dev/null +++ b/examples/gallery/simple/react-app/src/index.js @@ -0,0 +1,17 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import './index.css'; +import App from './App'; +import reportWebVitals from './reportWebVitals'; + +ReactDOM.render( + + + , + document.getElementById('root') +); + +// If you want to start measuring performance in your app, pass a function +// to log results (for example: reportWebVitals(console.log)) +// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals +reportWebVitals(); diff --git a/examples/gallery/simple/react-app/src/logo.svg b/examples/gallery/simple/react-app/src/logo.svg new file mode 100644 index 0000000..9dfc1c0 --- /dev/null +++ b/examples/gallery/simple/react-app/src/logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/gallery/simple/react-app/src/reportWebVitals.js b/examples/gallery/simple/react-app/src/reportWebVitals.js new file mode 100644 index 0000000..5253d3a --- /dev/null +++ b/examples/gallery/simple/react-app/src/reportWebVitals.js @@ -0,0 +1,13 @@ +const reportWebVitals = onPerfEntry => { + if (onPerfEntry && onPerfEntry instanceof Function) { + import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { + getCLS(onPerfEntry); + getFID(onPerfEntry); + getFCP(onPerfEntry); + getLCP(onPerfEntry); + getTTFB(onPerfEntry); + }); + } +}; + +export default reportWebVitals; diff --git a/examples/gallery/simple/react-app/src/setupTests.js b/examples/gallery/simple/react-app/src/setupTests.js new file mode 100644 index 0000000..8f2609b --- /dev/null +++ b/examples/gallery/simple/react-app/src/setupTests.js @@ -0,0 +1,5 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; diff --git a/examples/gallery/simple/uploader/README.md b/examples/gallery/simple/uploader/README.md new file mode 100644 index 0000000..1a2b0f2 --- /dev/null +++ b/examples/gallery/simple/uploader/README.md @@ -0,0 +1,20 @@ +# uploader + +A command line interface for uploading file image for react-gallery + +Execute the cmd passing in the path to the file you want upload. + +## Install + +``` + > npm install +``` + +## Run + +### Upload the asset folder + +``` + > BOX_ID=[YOUR_BOX_ID] node index.js +``` + diff --git a/examples/react-gallery/scripts/init.js b/examples/gallery/simple/uploader/index.js similarity index 94% rename from examples/react-gallery/scripts/init.js rename to examples/gallery/simple/uploader/index.js index 2585aba..b6ee679 100644 --- a/examples/react-gallery/scripts/init.js +++ b/examples/gallery/simple/uploader/index.js @@ -3,13 +3,13 @@ const fs=require('fs'); const { File } = require("@web-std/file") const wrtc = require("wrtc") -const PHOTOS_PATH= './scripts/photos/' +const PHOTOS_PATH= '../../assets/' const BOX_ID = process.env.BOX_ID async function main() { const fula = await createClient({wrtc}) - + console.log("BoxID:",BOX_ID) const conn = fula.connect(BOX_ID) conn.on('connected',async ()=>{ for await (const file of readFiles(PHOTOS_PATH)) { diff --git a/examples/gallery/simple/uploader/package.json b/examples/gallery/simple/uploader/package.json new file mode 100644 index 0000000..ad29081 --- /dev/null +++ b/examples/gallery/simple/uploader/package.json @@ -0,0 +1,14 @@ +{ + "name": "react-gallery-uploader", + "version": "0.1.0", + "private": true, + "main": "index.js", + "dependencies": { + "@web-std/file": "~3.0.2", + "wrtc": "~0.4.7", + "@functionland/fula": "~0.6.5" + }, + "scripts": { + "start": "node index.js" + } +} diff --git a/examples/react-todo-app/package.json b/examples/react-todo-app/package.json index e210000..7e8e705 100644 --- a/examples/react-todo-app/package.json +++ b/examples/react-todo-app/package.json @@ -3,6 +3,8 @@ "version": "0.1.0", "private": true, "dependencies": { + "@functionland/fula": "../../libraries/fula-client", + "@functionland/fula-client-react": "file:../../libraries/fula-client-react", "@testing-library/jest-dom": "^5.16.2", "@testing-library/react": "^12.1.3", "@testing-library/user-event": "^13.5.0", @@ -10,15 +12,13 @@ "@types/node": "~17.0.21", "@types/react": "~17.0.39", "@types/react-dom": "~17.0.9", + "graphql": "16.3.0", "react": "^17.0.2", "react-dom": "~17.0.2", "react-icons": "^4.3.1", "react-scripts": "5.0.0", "typescript": "~4.6.2", - "web-vitals": "^2.1.4", - "graphql":"16.3.0", - "@functionland/fula": "~0.6.4", - "@functionland/fula-client-react":"~0.1.6" + "web-vitals": "^2.1.4" }, "scripts": { "start": "react-scripts start", diff --git a/libraries/async-later/CHANGELOG.json b/libraries/async-later/CHANGELOG.json index 5d9386c..29775f5 100644 --- a/libraries/async-later/CHANGELOG.json +++ b/libraries/async-later/CHANGELOG.json @@ -1,6 +1,18 @@ { "name": "async-later", "entries": [ + { + "version": "0.1.11", + "tag": "async-later_v0.1.11", + "date": "Tue, 10 May 2022 06:52:04 GMT", + "comments": { + "patch": [ + { + "comment": "remove internal package from dep" + } + ] + } + }, { "version": "0.1.10", "tag": "async-later_v0.1.10", diff --git a/libraries/async-later/CHANGELOG.md b/libraries/async-later/CHANGELOG.md index 990b1d5..44d3fa2 100644 --- a/libraries/async-later/CHANGELOG.md +++ b/libraries/async-later/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - async-later -This log was last generated on Sun, 24 Apr 2022 09:20:16 GMT and should not be manually modified. +This log was last generated on Tue, 10 May 2022 06:52:04 GMT and should not be manually modified. + +## 0.1.11 +Tue, 10 May 2022 06:52:04 GMT + +### Patches + +- remove internal package from dep ## 0.1.10 Sun, 24 Apr 2022 09:20:16 GMT diff --git a/libraries/async-later/package.json b/libraries/async-later/package.json index 82695c9..be23037 100644 --- a/libraries/async-later/package.json +++ b/libraries/async-later/package.json @@ -1,6 +1,6 @@ { "name": "async-later", - "version": "0.1.10", + "version": "0.1.11", "description": "Functional directives for Promise and AsyncIterable", "types": "dist/types/src/index.d.ts", "main": "./dist/node/cjs.js", @@ -30,7 +30,6 @@ ], "license": "MIT", "devDependencies": { - "build-helpers": "~0.0.1", "esbuild": "~0.14.25", "streaming-iterables": "~6.2.0", "tap-spec": "~5.0.0", diff --git a/libraries/async-later/scripts/build.js b/libraries/async-later/scripts/build.js index 38aede2..f3fd35c 100644 --- a/libraries/async-later/scripts/build.js +++ b/libraries/async-later/scripts/build.js @@ -2,9 +2,6 @@ import { build } from 'esbuild'; import babel from 'esbuild-plugin-babel'; import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'; import {NodeModulesPolyfillPlugin} from '@esbuild-plugins/node-modules-polyfill' -import {clean} from 'build-helpers' - -clean() build({ entryPoints: ['src/index.ts'], diff --git a/libraries/fula-client-react/CHANGELOG.json b/libraries/fula-client-react/CHANGELOG.json index ad5c82a..1ca20d5 100644 --- a/libraries/fula-client-react/CHANGELOG.json +++ b/libraries/fula-client-react/CHANGELOG.json @@ -1,6 +1,23 @@ { "name": "@functionland/fula-client-react", "entries": [ + { + "version": "0.1.7", + "tag": "@functionland/fula-client-react_v0.1.7", + "date": "Tue, 10 May 2022 06:52:04 GMT", + "comments": { + "patch": [ + { + "comment": "remove internal package from dep" + } + ], + "dependency": [ + { + "comment": "Updating dependency \"@functionland/fula\" from `~0.6.4` to `~0.6.5`" + } + ] + } + }, { "version": "0.1.6", "tag": "@functionland/fula-client-react_v0.1.6", diff --git a/libraries/fula-client-react/CHANGELOG.md b/libraries/fula-client-react/CHANGELOG.md index 797da1f..5470148 100644 --- a/libraries/fula-client-react/CHANGELOG.md +++ b/libraries/fula-client-react/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - @functionland/fula-client-react -This log was last generated on Wed, 16 Mar 2022 13:51:21 GMT and should not be manually modified. +This log was last generated on Tue, 10 May 2022 06:52:04 GMT and should not be manually modified. + +## 0.1.7 +Tue, 10 May 2022 06:52:04 GMT + +### Patches + +- remove internal package from dep ## 0.1.6 Wed, 16 Mar 2022 13:51:21 GMT diff --git a/libraries/fula-client-react/package.json b/libraries/fula-client-react/package.json index 2a8ea0e..51a3776 100644 --- a/libraries/fula-client-react/package.json +++ b/libraries/fula-client-react/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/fula-client-react", - "version": "0.1.6", + "version": "0.1.7", "description": "This package provide some utility to use fula client in react projects", "type": "module", "types": "dist/types/index.d.ts", @@ -18,19 +18,17 @@ "type-check": "tsc" }, "peerDependencies": { - "react": "~17.0.2", - "react-dom": "17.0.2", "graphql": "16.2.0" }, "devDependencies": { - "@functionland/fula": "~0.6.4", + "@functionland/fula": "~0.6.5", + "@esbuild-plugins/esm-externals": "~0.0.6", "@types/jest": "~27.4.1", "@types/node": "~17.0.21", "@types/react": "~17.0.39", "@types/react-dom": "~17.0.9", "@typescript-eslint/eslint-plugin": "~5.13.0", "@typescript-eslint/parser": "~5.13.0", - "build-helpers": "~0.0.1", "esbuild": "~0.14.25", "prettier": "~2.5.1", "typescript": "~4.6.2" diff --git a/libraries/fula-client-react/scripts/build.js b/libraries/fula-client-react/scripts/build.js index fd42bab..04fbdc6 100644 --- a/libraries/fula-client-react/scripts/build.js +++ b/libraries/fula-client-react/scripts/build.js @@ -1,7 +1,6 @@ import { build } from 'esbuild'; -import { clean } from 'build-helpers' +import {EsmExternalsPlugin} from '@esbuild-plugins/esm-externals' -clean() await build({ entryPoints: ['src/index.ts'], @@ -9,11 +8,9 @@ await build({ target: 'es2018', format: 'esm', bundle: true, - sourcemap: true, + sourcemap: false, outfile: 'dist/br/index.js', - external: [ - 'react','react-dom' - ] + plugins: [EsmExternalsPlugin({ externals: ['react', 'react-dom'] })] }); diff --git a/libraries/fula-client-react/tsconfig.json b/libraries/fula-client-react/tsconfig.json index 7b2f93c..7cf94e7 100644 --- a/libraries/fula-client-react/tsconfig.json +++ b/libraries/fula-client-react/tsconfig.json @@ -15,6 +15,7 @@ "allowSyntheticDefaultImports": true, "emitDeclarationOnly": true, "declaration": true, + "skipLibCheck": true, "declarationDir": "dist/types", "jsx": "react-jsx" }, diff --git a/libraries/fula-client/CHANGELOG.json b/libraries/fula-client/CHANGELOG.json index 1b912b3..cab8be8 100644 --- a/libraries/fula-client/CHANGELOG.json +++ b/libraries/fula-client/CHANGELOG.json @@ -1,6 +1,26 @@ { "name": "@functionland/fula", "entries": [ + { + "version": "0.6.5", + "tag": "@functionland/fula_v0.6.5", + "date": "Tue, 10 May 2022 06:52:04 GMT", + "comments": { + "patch": [ + { + "comment": "remove internal package from dep" + } + ], + "dependency": [ + { + "comment": "Updating dependency \"@functionland/file-protocol\" from `~0.3.5` to `~0.3.6`" + }, + { + "comment": "Updating dependency \"@functionland/graph-protocol\" from `~0.2.1` to `~0.2.2`" + } + ] + } + }, { "version": "0.6.4", "tag": "@functionland/fula_v0.6.4", diff --git a/libraries/fula-client/CHANGELOG.md b/libraries/fula-client/CHANGELOG.md index 4be5840..2e9e3eb 100644 --- a/libraries/fula-client/CHANGELOG.md +++ b/libraries/fula-client/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - @functionland/fula -This log was last generated on Mon, 25 Apr 2022 07:43:12 GMT and should not be manually modified. +This log was last generated on Tue, 10 May 2022 06:52:04 GMT and should not be manually modified. + +## 0.6.5 +Tue, 10 May 2022 06:52:04 GMT + +### Patches + +- remove internal package from dep ## 0.6.4 Mon, 25 Apr 2022 07:43:12 GMT diff --git a/libraries/fula-client/package.json b/libraries/fula-client/package.json index 1427301..632f550 100644 --- a/libraries/fula-client/package.json +++ b/libraries/fula-client/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/fula", - "version": "0.6.4", + "version": "0.6.5", "description": "Fula client for building Box Dapp", "type": "module", "main": "dist/node/index.js", @@ -42,8 +42,8 @@ "@esbuild-plugins/esm-externals": "~0.0.6", "@esbuild-plugins/node-globals-polyfill": "~0.1.1", "@esbuild-plugins/node-modules-polyfill": "~0.1.4", - "@functionland/file-protocol": "~0.3.5", - "@functionland/graph-protocol": "~0.2.1", + "@functionland/file-protocol": "~0.3.6", + "@functionland/graph-protocol": "~0.2.2", "@ipld/schema-validation": "~1.1.0", "@types/aes-js": "^3.1.1", "@types/browserify": "~12.0.37", @@ -54,7 +54,6 @@ "@web-std/file": "~3.0.2", "browserify": "~17.0.0", "buffer": "~6.0.3", - "build-helpers": "~0.0.1", "debug": "~4.3.3", "esbuild": "~0.14.25", "esbuild-plugin-babel": "~0.2.3", diff --git a/libraries/fula-client/scripts/build.js b/libraries/fula-client/scripts/build.js index c921f95..a478d93 100644 --- a/libraries/fula-client/scripts/build.js +++ b/libraries/fula-client/scripts/build.js @@ -1,8 +1,7 @@ import {NodeGlobalsPolyfillPlugin} from '@esbuild-plugins/node-globals-polyfill'; import {build} from 'esbuild'; -import {clean} from 'build-helpers' +import babel from 'esbuild-plugin-babel'; -clean() await build({ entryPoints: ['src/index.ts'], platform: 'browser', @@ -11,19 +10,24 @@ await build({ bundle: true, sourcemap: false, outfile: 'dist/web/index.js', + minifySyntax: true, + minify: true, define: { global: 'globalThis' }, plugins: [ + NodeGlobalsPolyfillPlugin({ process: true, buffer: true, define: {'process.env.NODE_ENV': '"dev"'} // inject will override define, to keep env vars you must also pass define here https://github.com/evanw/esbuild/issues/660 - }) - ] + }), + ], + external:['@chainsafe/libp2p-noise','libp2p'] }); + await build({ entryPoints: ['src/index.ts'], platform: 'node', diff --git a/libraries/fula-client/tsconfig.json b/libraries/fula-client/tsconfig.json index e5ae495..72b57af 100644 --- a/libraries/fula-client/tsconfig.json +++ b/libraries/fula-client/tsconfig.json @@ -15,7 +15,8 @@ "rootDir": "./", "emitDeclarationOnly": true, "declaration": true, - "declarationDir": "dist/types" + "declarationDir": "dist/types", + "skipLibCheck": true }, "include": [ "src/**/*" diff --git a/libraries/fula-sec/.npmignore b/libraries/fula-sec/.npmignore new file mode 100644 index 0000000..cc759a3 --- /dev/null +++ b/libraries/fula-sec/.npmignore @@ -0,0 +1,4 @@ +* +!dist/**/* +dist/tests/**/* +!src/**/* diff --git a/libraries/fula-sec/CHANGELOG.json b/libraries/fula-sec/CHANGELOG.json new file mode 100644 index 0000000..bf69e6e --- /dev/null +++ b/libraries/fula-sec/CHANGELOG.json @@ -0,0 +1,17 @@ +{ + "name": "@functionland/fula-sec", + "entries": [ + { + "version": "1.0.1", + "tag": "@functionland/fula-sec_v1.0.1", + "date": "Tue, 10 May 2022 06:52:04 GMT", + "comments": { + "patch": [ + { + "comment": "remove internal package from dep and aligne deps" + } + ] + } + } + ] +} diff --git a/libraries/fula-sec/CHANGELOG.md b/libraries/fula-sec/CHANGELOG.md new file mode 100644 index 0000000..c4e051c --- /dev/null +++ b/libraries/fula-sec/CHANGELOG.md @@ -0,0 +1,11 @@ +# Change Log - @functionland/fula-sec + +This log was last generated on Tue, 10 May 2022 06:52:04 GMT and should not be manually modified. + +## 1.0.1 +Tue, 10 May 2022 06:52:04 GMT + +### Patches + +- remove internal package from dep and aligne deps + diff --git a/libraries/fula-sec/package.json b/libraries/fula-sec/package.json index 660f759..3b859fc 100644 --- a/libraries/fula-sec/package.json +++ b/libraries/fula-sec/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/fula-sec", - "version": "1.0.0", + "version": "0.6.5", "description": "", "type": "module", "types": "dist/types/src/index.d.ts", @@ -14,46 +14,48 @@ "doc": "npx typedoc src/*.ts" }, "keywords": [], - "author": "", + "author": "jamshid@fx.land", "license": "ISC", "devDependencies": { - "@types/chai": "^4.3.0", - "@types/mocha": "^9.1.0", - "@types/node": "^17.0.21", - "@types/tape": "^4.13.2", + "@types/chai": "~4.3.0", + "@types/mocha": "~9.1.0", + "@types/node": "~17.0.21", + "@types/tape": "~4.13.2", "esbuild-runner": "~2.2.1", - "@typescript-eslint/eslint-plugin": "^5.13.0", - "@typescript-eslint/parser": "^5.13.0", + "@typescript-eslint/eslint-plugin": "~5.13.0", + "@typescript-eslint/parser": "~5.13.0", "@esbuild-plugins/node-globals-polyfill": "~0.1.1", "@esbuild-plugins/node-modules-polyfill": "~0.1.4", "build-helpers": "~0.0.1", - "dids": "3.0.0-alpha.12", - "chai": "^4.3.6", - "eslint": "^8.10.0", + "chai": "~4.3.6", + "eslint": "~8.10.0", "esbuild": "~0.14.25", - "ethers": "^5.6.4", - "ts-mocha": "^9.0.2", - "mocha": "^9.2.1", - "ts-node": "^10.6.0", - "typedoc": "^0.22.12", - "typescript": "^4.6.2", - "key-did-resolver": "^1.4.4", - "key-did-provider-ed25519": "^1.1.0", - "uint8arrays": "^3.0.0", - "buffer": "^6.0.3" + "ethers": "~5.6.4", + "ts-mocha": "~9.0.2", + "mocha": "~9.2.1", + "ts-node": "~10.6.0", + "typedoc": "~0.22.12", + "typescript": "~4.6.2", + "key-did-resolver": "~1.4.4", + "key-did-provider-ed25519": "~1.1.0", + "uint8arrays": "~3.0.0", + "buffer": "~6.0.3" }, "dependencies": { - "@stablelib/x25519": "^1.0.2", - "ethers": "^5.6.4", - "did-jwt": "^5.12.4", - "dids": "^2.4.3", - "key-did-provider-ed25519": "^1.1.0", - "key-did-resolver": "^1.4.4" + "@stablelib/x25519": "~1.0.2", + "ethers": "~5.6.4", + "did-jwt": "~5.12.4", + "dids": "3.0.0-alpha.12", + "key-did-provider-ed25519": "~1.1.0", + "key-did-resolver": "~1.4.4" }, "exports": { ".": { "browser": { "default": "./dist/br/index.js" + }, + "node": { + "require":"./dist/node/index.cjs" } } } diff --git a/libraries/fula-sec/scripts/build-test.js b/libraries/fula-sec/scripts/build-test.js index 769524e..7b9d95f 100644 --- a/libraries/fula-sec/scripts/build-test.js +++ b/libraries/fula-sec/scripts/build-test.js @@ -1,8 +1,5 @@ -import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'; -import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'; import { build } from 'esbuild'; -// import browserify from 'browserify'; -// import * as fs from 'fs' + await build({ entryPoints: ['tests/asym.enc.test.ts','tests/tagged.enc.test.ts','tests/did.test.ts'], diff --git a/libraries/fula-sec/scripts/build.js b/libraries/fula-sec/scripts/build.js index d580e96..998b003 100644 --- a/libraries/fula-sec/scripts/build.js +++ b/libraries/fula-sec/scripts/build.js @@ -1,7 +1,4 @@ import { build } from 'esbuild'; -import { clean } from 'build-helpers' - -clean() await build({ entryPoints: ['src/index.ts'], @@ -9,13 +6,18 @@ await build({ target: 'es2018', format: 'esm', bundle: true, - sourcemap: true, + sourcemap: false, outfile: 'dist/br/index.js', - external: [ - 'react','react-dom', - ] }); +await build({ + entryPoints: ['src/index.ts'], + platform: 'node', + format: 'cjs', + bundle: true, + sourcemap: false, + outfile: 'dist/node/index.cjs' +}); diff --git a/libraries/fula-sec/tsconfig.json b/libraries/fula-sec/tsconfig.json index 15588d3..1bd7422 100644 --- a/libraries/fula-sec/tsconfig.json +++ b/libraries/fula-sec/tsconfig.json @@ -14,7 +14,10 @@ "esModuleInterop": true, "resolveJsonModule": true, "importHelpers": false, - "skipLibCheck": true + "skipLibCheck": true, + "emitDeclarationOnly": true, + "declaration": true, + "declarationDir": "dist/types" }, "typedocOptions": { "entryPoints": ["src/did.ts"], diff --git a/protocols/file/CHANGELOG.json b/protocols/file/CHANGELOG.json index 5357c30..a74cf12 100644 --- a/protocols/file/CHANGELOG.json +++ b/protocols/file/CHANGELOG.json @@ -1,6 +1,23 @@ { "name": "@functionland/file-protocol", "entries": [ + { + "version": "0.3.6", + "tag": "@functionland/file-protocol_v0.3.6", + "date": "Tue, 10 May 2022 06:52:04 GMT", + "comments": { + "patch": [ + { + "comment": "remove internal package from dep" + } + ], + "dependency": [ + { + "comment": "Updating dependency \"async-later\" from `0.1.10` to `0.1.11`" + } + ] + } + }, { "version": "0.3.5", "tag": "@functionland/file-protocol_v0.3.5", diff --git a/protocols/file/CHANGELOG.md b/protocols/file/CHANGELOG.md index 3d481d1..d77975d 100644 --- a/protocols/file/CHANGELOG.md +++ b/protocols/file/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - @functionland/file-protocol -This log was last generated on Sun, 24 Apr 2022 09:20:16 GMT and should not be manually modified. +This log was last generated on Tue, 10 May 2022 06:52:04 GMT and should not be manually modified. + +## 0.3.6 +Tue, 10 May 2022 06:52:04 GMT + +### Patches + +- remove internal package from dep ## 0.3.5 Sun, 24 Apr 2022 09:20:16 GMT diff --git a/protocols/file/package.json b/protocols/file/package.json index 2d2ce76..dd4b622 100644 --- a/protocols/file/package.json +++ b/protocols/file/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/file-protocol", - "version": "0.3.5", + "version": "0.3.6", "description": "", "types": "dist/types/src/index.d.ts", "main": "./dist/node/cjs.cjs", @@ -36,11 +36,10 @@ "@types/pako": "~1.0.3", "@typescript-eslint/eslint-plugin": "~5.13.0", "@typescript-eslint/parser": "~5.13.0", - "build-helpers": "~0.0.1", "esbuild": "~0.14.25", "esbuild-plugin-babel": "~0.2.3", "eslint": "~8.10.0", - "async-later": "0.1.10", + "async-later": "0.1.11", "it-pipe": "~2.0.3", "it-stream-types": "^1.0.4", "libp2p": "~0.36.2", diff --git a/protocols/file/scripts/build.js b/protocols/file/scripts/build.js index 7464afc..c6f2128 100644 --- a/protocols/file/scripts/build.js +++ b/protocols/file/scripts/build.js @@ -1,9 +1,8 @@ import esbuild from 'esbuild'; import path from 'path'; import babel from 'esbuild-plugin-babel'; -import {clean} from 'build-helpers' -clean() + esbuild.build({ entryPoints: ['src/index.ts'], platform: 'browser', diff --git a/protocols/graph/CHANGELOG.json b/protocols/graph/CHANGELOG.json index 6d8e313..6a9ec8c 100644 --- a/protocols/graph/CHANGELOG.json +++ b/protocols/graph/CHANGELOG.json @@ -1,6 +1,23 @@ { "name": "@functionland/graph-protocol", "entries": [ + { + "version": "0.2.2", + "tag": "@functionland/graph-protocol_v0.2.2", + "date": "Tue, 10 May 2022 06:52:04 GMT", + "comments": { + "patch": [ + { + "comment": "remove internal package from dep" + } + ], + "dependency": [ + { + "comment": "Updating dependency \"async-later\" from `0.1.10` to `0.1.11`" + } + ] + } + }, { "version": "0.2.1", "tag": "@functionland/graph-protocol_v0.2.1", diff --git a/protocols/graph/CHANGELOG.md b/protocols/graph/CHANGELOG.md index 8febe7b..92a1d9d 100644 --- a/protocols/graph/CHANGELOG.md +++ b/protocols/graph/CHANGELOG.md @@ -1,6 +1,13 @@ # Change Log - @functionland/graph-protocol -This log was last generated on Sun, 24 Apr 2022 09:20:16 GMT and should not be manually modified. +This log was last generated on Tue, 10 May 2022 06:52:04 GMT and should not be manually modified. + +## 0.2.2 +Tue, 10 May 2022 06:52:04 GMT + +### Patches + +- remove internal package from dep ## 0.2.1 Sun, 24 Apr 2022 09:20:16 GMT diff --git a/protocols/graph/package.json b/protocols/graph/package.json index e3bf576..8dbff40 100644 --- a/protocols/graph/package.json +++ b/protocols/graph/package.json @@ -1,6 +1,6 @@ { "name": "@functionland/graph-protocol", - "version": "0.2.1", + "version": "0.2.2", "description": "", "types": "dist/types/src/index.d.ts", "main": "./dist/node/cjs.cjs", @@ -20,7 +20,7 @@ "@babel/runtime": "~7.17.2" }, "devDependencies": { - "async-later": "0.1.10", + "async-later": "0.1.11", "it-pipe": "~2.0.3", "multiformats": "~9.6.4", "rxjs": "~7.5.4", @@ -28,7 +28,6 @@ "peer-id": "~0.16.0", "@esbuild-plugins/node-globals-polyfill": "~0.1.1", "@esbuild-plugins/node-modules-polyfill": "~0.1.4", - "build-helpers": "~0.0.1", "tslib": "~2.3.1", "@protobuf-ts/plugin": "~2.2.2", "@types/bl": "~5.0.2", diff --git a/protocols/graph/scripts/build.js b/protocols/graph/scripts/build.js index 7464afc..c6f2128 100644 --- a/protocols/graph/scripts/build.js +++ b/protocols/graph/scripts/build.js @@ -1,9 +1,8 @@ import esbuild from 'esbuild'; import path from 'path'; import babel from 'esbuild-plugin-babel'; -import {clean} from 'build-helpers' -clean() + esbuild.build({ entryPoints: ['src/index.ts'], platform: 'browser', diff --git a/rush.json b/rush.json index 1b120f4..5449237 100644 --- a/rush.json +++ b/rush.json @@ -63,12 +63,6 @@ "reviewCategory": "production", "shouldPublish": true }, - { - "packageName": "@functionland/rn-fula", - "projectFolder": "libraries/rn-fula", - "reviewCategory": "production", - "shouldPublish": false - }, { "packageName": "@functionland/file-protocol", "projectFolder": "protocols/file", @@ -81,39 +75,18 @@ "reviewCategory": "production", "shouldPublish": true }, - { - "packageName": "@functionland/fx", - "projectFolder": "tools/cli", - "reviewCategory": "prototypes" - }, { "packageName": "@functionland/box", "projectFolder": "apps/box", "reviewCategory": "production", "shouldPublish": true }, - { - "packageName": "@functionland/signal", - "projectFolder": "apps/signal", - "reviewCategory": "production" - }, { "packageName": "@functionland/fula-sec", "projectFolder": "libraries/fula-sec", "reviewCategory": "production", "shouldPublish": true }, - { - "packageName": "react-todo-app", - "projectFolder": "examples/react-todo-app", - "reviewCategory": "prototypes" - - }, - { - "packageName": "react-gallery", - "projectFolder": "examples/react-gallery", - "reviewCategory": "prototypes" - }, { "packageName": "build-helpers", "projectFolder": "tools/build-helpers",