diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 0000000..fd147cf --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -0,0 +1,45 @@ +# Compares the version in package.json to tags on the repo. If the tag doesn't exist, a new tag is created, which +# then triggers the normal "on tag" release automation in the build job +name: Auto Tag + +on: + push: + branches: + - main + +concurrency: + group: main-release-check + +jobs: + check-version: + name: Check version increment + runs-on: ubuntu-latest + steps: + - uses: Chia-Network/actions/clean-workspace@main + + - name: Checkout current branch + uses: actions/checkout@v3 + with: + # Need PACKAGE_ADMIN_PAT token so when the tag is created, the tag automation runs + token: ${{ secrets.PACKAGE_ADMIN_PAT }} + fetch-depth: 0 + + - name: Check for current version tag. Create if it doesn't exist + run: | + version=$(cat $GITHUB_WORKSPACE/package.json | jq -r '.version') + echo "Version is: $version" + + if [ $(git tag -l "$version") ]; then + echo "Tag exists, nothing to do" + else + echo "Tag does not exist. Creating and pushing tag" + rm -f CHANGELOG.md + npx conventional-changelog-cli -p angular -i CHANGELOG.md -s -r 0 + git add CHANGELOG.md + git config --global user.name 'ChiaAutomation' + git config --global user.email 'automation@chia.net' + git commit -m "Updating changelog for $version" + git tag $version + git push origin $version + git push origin main + fi diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..094628d --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,200 @@ +name: Build Binaries + +on: + push: + branches: + - main + tags: + - '**' + pull_request: + branches: + - '**' + +concurrency: + group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }} + cancel-in-progress: true + +jobs: + build: + name: Build Binaries + runs-on: ${{ matrix.runs-on }} + strategy: + matrix: + include: + - runs-on: ubuntu-latest + artifact-name: linux-x64 + build-command: npm run create-linux-x64-dist + - runs-on: macos-latest + artifact-name: macos-x64 + build-command: npm run create-mac-x64-dist + - runs-on: windows-2019 + artifact-name: windows-x64 + build-command: npm run create-win-x64-dist + + steps: + - uses: Chia-Network/actions/clean-workspace@main + + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Setup Node 16.x + uses: actions/setup-node@v2.4.1 + with: + node-version: '16.0.0' + + - name: Ignore Husky + run: npm set-script prepare "" + if: matrix.runs-on != 'windows-2019' + + - name: npm install + run: | + node --version + npm install + + - name: npm cache clear --force + run: npm cache clear --force + + - name: npm cache rm + run: npm cache rm --force + + - name: npm cache verify + run: npm cache verify + + - name: install global packages + run: npm i -g @babel/cli @babel/preset-env pkg + + - name: create distributions + run: ${{ matrix.build-command }} + + - name: Make executable + run: chmod +x dist/climate-portal + +### If using sqlite, uncomment the following 2 sections ### +### and add a line to sign the sqlite binaries in the ### +### Mac section. ### + +# - name: Copy sqlite3 (non windows) +# run: cp ./node_modules/sqlite3/build/Release/node_sqlite3.node ./dist/ +# if: matrix.runs-on != 'windows-2019' + +# - name: Copy sqlite3 (windows) +# run: cp .\node_modules\sqlite3\build\Release\node_sqlite3.node .\dist\ +# if: matrix.runs-on == 'windows-2019' + + # Windows Code Signing + - name: Decode code signing cert into an encrypted file + if: matrix.runs-on == 'windows-2019' + uses: kitek/decode-base64-into-file-action@1.0 + with: + encoded-value: ${{ secrets.WIN_CODE_SIGN_CERT }} + destination-file: .\win_code_sign_cert.pfx + + - name: Sign windows artifacts + if: matrix.runs-on == 'windows-2019' + uses: chia-network/actions/sign/windows@main + with: + certificate_path: .\win_code_sign_cert.pfx + certificate_password: ${{ secrets.WIN_CODE_SIGN_PASSWORD }} + file: ${{ github.workspace }}/dist/climate-portal.exe + + # Mac .pkg build + sign + - name: Import Apple installer signing certificate + #if: steps.check_secrets.outputs.HAS_SECRET + if: matrix.runs-on == 'macos-latest' + uses: Apple-Actions/import-codesign-certs@v1 + with: + keychain-password: ${{ secrets.KEYCHAIN_PASSWORD }} + p12-file-base64: ${{ secrets.APPLE_DEV_ID_INSTALLER }} + p12-password: ${{ secrets.APPLE_DEV_ID_INSTALLER_PASS }} + + - name: Import Apple Application signing certificate + #if: steps.check_secrets.outputs.HAS_SECRET + if: matrix.runs-on == 'macos-latest' + uses: Apple-Actions/import-codesign-certs@v1 + with: + create-keychain: false # Created when importing the first cert + keychain-password: ${{ secrets.KEYCHAIN_PASSWORD }} + p12-file-base64: ${{ secrets.APPLE_DEV_ID_APP }} + p12-password: ${{ secrets.APPLE_DEV_ID_APP_PASS }} + + - name: Build Mac .pkg + if: matrix.runs-on == 'macos-latest' + run: | + rm -rf ${{ github.workspace }}/build-scripts/macos/darwin/application || true + cp -r ${{ github.workspace }}/dist ${{ github.workspace }}/build-scripts/macos/application + + echo "Signing the binaries" + codesign -f -s "Developer ID Application: Chia Network Inc." --timestamp --options=runtime --entitlements ${{ github.workspace }}/build-scripts/macos/entitlements.mac.plist ${{ github.workspace }}/build-scripts/macos/application/climate-portal + + # Makes the .pkg in ./build-scripts/macos/target/pkg + echo "Building the .pkg" + bash ${{ github.workspace }}/build-scripts/macos/build-macos.sh ClimatePortal + + mkdir -p ${{ github.workspace }}/build-scripts/macos/target/pkg-signed + + echo "Signing the .pkg" + productsign --sign "Developer ID Installer: Chia Network Inc." ${{ github.workspace }}/build-scripts/macos/target/pkg/ClimatePortal-macos-installer-x64.pkg ${{ github.workspace }}/build-scripts/macos/target/pkg-signed/ClimatePortal-macos-installer-x64.pkg + + echo "Notarizing the .pkg" + npm install -g notarize-cli + notarize-cli \ + --file=${{ github.workspace }}/build-scripts/macos/target/pkg-signed/ClimatePortal-macos-installer-x64.pkg \ + --bundle-id net.chia.climate-portal \ + --username "${{ secrets.APPLE_NOTARIZE_USERNAME }}" \ + --password "${{ secrets.APPLE_NOTARIZE_PASSWORD }}" + + - name: Upload Mac Installer + if: matrix.runs-on == 'macos-latest' + uses: actions/upload-artifact@v2 + with: + name: mac-installer + path: ${{ github.workspace }}/build-scripts/macos/target/pkg-signed + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: ${{ matrix.artifact-name }} + path: ${{ github.workspace }}/dist + + release: + runs-on: ubuntu-latest + if: startsWith(github.ref, 'refs/tags/') + needs: + - build + steps: + - name: Download Windows artifacts + uses: actions/download-artifact@v2 + with: + name: windows-x64 + path: windows-x64 + + - name: Download MacOS artifacts + uses: actions/download-artifact@v2 + with: + name: mac-installer + path: mac-installer + + - name: Download Linux artifacts + uses: actions/download-artifact@v2 + with: + name: linux-x64 + path: linux-x64 + + - name: Get tag name + id: tag-name + run: | + echo ::set-output name=TAGNAME::$(echo $GITHUB_REF | cut -d / -f 3) + + - name: Create zips + run: | + zip -r windows-x64-${{ steps.tag-name.outputs.TAGNAME }}.zip windows-x64 + zip -r macos-x64-${{ steps.tag-name.outputs.TAGNAME }}.zip mac-installer + zip -r linux-x64-${{ steps.tag-name.outputs.TAGNAME }}.zip linux-x64 + + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: | + windows-x64-${{ steps.tag-name.outputs.TAGNAME }}.zip + macos-x64-${{ steps.tag-name.outputs.TAGNAME }}.zip + linux-x64-${{ steps.tag-name.outputs.TAGNAME }}.zip diff --git a/.github/workflows/ensure-version-increment.yml b/.github/workflows/ensure-version-increment.yml new file mode 100644 index 0000000..4938132 --- /dev/null +++ b/.github/workflows/ensure-version-increment.yml @@ -0,0 +1,42 @@ +# This workflow runs on any PRs that are targeting main, and ensures that the version in package.json is incremented +name: Check Version Increment + +on: + pull_request: + branches: + - 'main' + +concurrency: + # SHA is added to the end if on `main` to let all main workflows run + group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}-${{ github.ref == 'refs/heads/main' && github.sha || '' }} + cancel-in-progress: true + +jobs: + check-version: + name: Check version increment + runs-on: ubuntu-latest + steps: + - uses: Chia-Network/actions/clean-workspace@main + + - name: Checkout current branch + uses: actions/checkout@v2 + with: + path: branch-repo + + - name: Checkout main + uses: actions/checkout@v2 + with: + ref: main + path: main-repo + + - name: Check Versions + run: | + main_version=$(cat $GITHUB_WORKSPACE/main-repo/package.json | jq -r '.version') + branch_version=$(cat $GITHUB_WORKSPACE/branch-repo/package.json | jq -r '.version') + echo "Main version: $main_version" + echo "Branch version: $branch_version" + + if [[ "$branch_version" == "$main_version" ]]; then + echo "Version in package.json on this branch is not changing. Version must incremenet for a merge to main" + exit 1 + fi diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..43ae75e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,54 @@ +## 1.0.1 (2022-11-11) + + +### Bug Fixes + +* add orgUid to proxy requests ([5ef63c8](https://github.com/Chia-Network/Climate-Portal/commit/5ef63c85f84a1e6c441aabf87213a2de2583c86d)) +* orguid update is not working ([3b8353d](https://github.com/Chia-Network/Climate-Portal/commit/3b8353de47075a5f44b1ba5193a5322e70292fad)) +* tokenize validation ([fcb8072](https://github.com/Chia-Network/Climate-Portal/commit/fcb80727b4bf7e29be58130d67d4eea0a3e16e27)) +* wallet holder ([14e85b4](https://github.com/Chia-Network/Climate-Portal/commit/14e85b4a476117133bffbd1b2117f7ee1b39392b)) + + +### Features + +* add default fee ([a5eb659](https://github.com/Chia-Network/Climate-Portal/commit/a5eb659ebbb16ac20eea5b58cecfd4ea5f0754cb)) +* add hoi validation ([1ad37ce](https://github.com/Chia-Network/Climate-Portal/commit/1ad37ce0131c16f19f3a1d61a51b1549e81fbb80)) +* add home org does not exist error ([889ad46](https://github.com/Chia-Network/Climate-Portal/commit/889ad46ea20482dee466eff24dff0bd0452b8545)) +* add orguid header ([6c60392](https://github.com/Chia-Network/Climate-Portal/commit/6c6039281d9c86280611c80420a14a8498ecb874)) +* add orgUid to all headers ([ea238f5](https://github.com/Chia-Network/Climate-Portal/commit/ea238f5afb881823eb8b0c14b739676cf8056b17)) +* add pagination by adding the pagination params to the proxy ([7a26759](https://github.com/Chia-Network/Climate-Portal/commit/7a267595092254ca4ef5e210aab06c54df42b3c7)) +* add pagination by adding the pagination params to the proxy ([0d07b60](https://github.com/Chia-Network/Climate-Portal/commit/0d07b60aa1ad605e0cca7fadcbef7949081ebfc2)) +* add projects endpoint proxy ([937597c](https://github.com/Chia-Network/Climate-Portal/commit/937597ce83bfb42cdd20b4ee5f853352b9aeccc6)) +* add proxy requests ([5309cfa](https://github.com/Chia-Network/Climate-Portal/commit/5309cfad54c33ed3ca2a714d61fbdd3e3155b476)) +* add tokenize endpoint ([90df4bf](https://github.com/Chia-Network/Climate-Portal/commit/90df4bfe06cc7ccc8dc9027cc28e687c4a81f753)) +* add tokenize endpoint ([1af0619](https://github.com/Chia-Network/Climate-Portal/commit/1af06192d90a07653ac7a2ad2962e607c5e2f63d)) +* add tokenize endpoint ([c45b275](https://github.com/Chia-Network/Climate-Portal/commit/c45b2751826374d57e3e73bebe768ca9674d8fa4)) +* add tokenize endpoint ([ebc94f8](https://github.com/Chia-Network/Climate-Portal/commit/ebc94f8be5a06d5aafc1e3e5cc302e3d740b9a4a)) +* add tokenize endpoint ([f3547f7](https://github.com/Chia-Network/Climate-Portal/commit/f3547f7814fc69bc32222f150d87692570d5e400)) +* add tokenize endpoint ([44869cd](https://github.com/Chia-Network/Climate-Portal/commit/44869cd7dfec5a7b72bfa9c70dab335bb63f9286)) +* add tokenize endpoint ([88fc089](https://github.com/Chia-Network/Climate-Portal/commit/88fc0899fe20cb3c801763f5bfca8f369e7162d7)) +* add tokenize endpoint ([ba0ee80](https://github.com/Chia-Network/Climate-Portal/commit/ba0ee806b99ca763e7e59adea3045153bd71db21)) +* add tokenize endpoint ([0ebbab8](https://github.com/Chia-Network/Climate-Portal/commit/0ebbab89cdd614d667bd5eefe2feb4c35b92c285)) +* add tokenize endpoint ([250e139](https://github.com/Chia-Network/Climate-Portal/commit/250e139f7e72d8ab0f2f75f67d1e1308c72841c9)) +* add yaml ([1ec6417](https://github.com/Chia-Network/Climate-Portal/commit/1ec641704600e3a838521fe303b825702ca3dd5f)) +* add yaml ([3d06d9e](https://github.com/Chia-Network/Climate-Portal/commit/3d06d9ea0146e0dd36b0832719f296e40ecf36c0)) +* config option to update climate warehouse units ([295b297](https://github.com/Chia-Network/Climate-Portal/commit/295b2978b6fe7477ba42b55aaebd7bd3826c2b42)) +* detokenize ([a2429df](https://github.com/Chia-Network/Climate-Portal/commit/a2429df0c69a49a9611ccfe2a3d8007622576c86)) +* detokenize ([43d36b0](https://github.com/Chia-Network/Climate-Portal/commit/43d36b0e88b2744ef6a275c138b7af5c7755533d)) +* get sore ids from datalayer ([8f741ef](https://github.com/Chia-Network/Climate-Portal/commit/8f741efa712db1a7574f68cbf937fbf840fb2fc3)) +* get store ids from datalayer ([6b837c6](https://github.com/Chia-Network/Climate-Portal/commit/6b837c635889747b481eaa7c55f0938059fdb348)) +* get store ids from datalayer ([b0eee6e](https://github.com/Chia-Network/Climate-Portal/commit/b0eee6e17527c06cbea52c39dc01dcec0658cbc4)) +* get store ids from datalayer ([da96dd2](https://github.com/Chia-Network/Climate-Portal/commit/da96dd23e407bae091ae9ec9d7cb085d8bbf0d2c)) +* get store ids from datalayer ([d0d759b](https://github.com/Chia-Network/Climate-Portal/commit/d0d759ba2b6462e8368aed81143a0b8fd819260c)) +* package into executable ([a36c062](https://github.com/Chia-Network/Climate-Portal/commit/a36c062b90990de315863c39c43ec9d8ac06a402)) +* remove default fee ([32494fe](https://github.com/Chia-Network/Climate-Portal/commit/32494fe1b633b5990d876ee348535be6736c6f9a)) +* remove fee field ([ff0b071](https://github.com/Chia-Network/Climate-Portal/commit/ff0b071f83a27cc2a1f3350b60d89d71a503a159)) +* replace detok file with detok string ([5701455](https://github.com/Chia-Network/Climate-Portal/commit/5701455768b2d61522854b49a5ca7b719681533b)) +* replace detok file with detok string ([76a8627](https://github.com/Chia-Network/Climate-Portal/commit/76a862791affba9790da1c707a9aebe47591c643)) +* return data for ui from detok-file endpoint ([2fd3e89](https://github.com/Chia-Network/Climate-Portal/commit/2fd3e899710449593e3b857d46e2b6595cd1f4b9)) +* return data for ui from detok-file endpoint ([66cf8a9](https://github.com/Chia-Network/Climate-Portal/commit/66cf8a95d8dc0c89d775ef05ec6e2e76b7fa9201)) +* send detok confirmation ([89c9d7d](https://github.com/Chia-Network/Climate-Portal/commit/89c9d7de5c0cebceaf4f488c6f967c2d720ee11e)) +* set parse detok unit information to amount in detok file ([0ed694a](https://github.com/Chia-Network/Climate-Portal/commit/0ed694a0ea0bc580842738640e9691a1318a6e60)) + + + diff --git a/build-scripts/macos/build-macos.sh b/build-scripts/macos/build-macos.sh new file mode 100755 index 0000000..76a6a44 --- /dev/null +++ b/build-scripts/macos/build-macos.sh @@ -0,0 +1,151 @@ +#!/bin/bash + +#Configuration Variables and Parameters + +#Parameters +SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" +TARGET_DIRECTORY="$SCRIPTPATH/target" +PRODUCT=${1} +DATE=`date +%Y-%m-%d` +TIME=`date +%H:%M:%S` +LOG_PREFIX="[$DATE $TIME]" + +function printUsage() { + echo -e "\033[1mUsage:\033[0m" + echo "$0 [APPLICATION_NAME]" + echo + echo -e "\033[1mOptions:\033[0m" + echo " -h (--help)" + echo + echo -e "\033[1mExample::\033[0m" + echo "$0 wso2am 2.6.0" + +} + +#Argument validation +if [[ "$1" == "-h" || "$1" == "--help" ]]; then + printUsage + exit 1 +fi +if [ -z "$1" ]; then + echo "Please enter a valid application name for your application" + echo + printUsage + exit 1 +else + echo "Application Name : $1" +fi + +#Functions +go_to_dir() { + pushd $1 >/dev/null 2>&1 +} + +log_info() { + echo "${LOG_PREFIX}[INFO]" $1 +} + +log_warn() { + echo "${LOG_PREFIX}[WARN]" $1 +} + +log_error() { + echo "${LOG_PREFIX}[ERROR]" $1 +} + +deleteInstallationDirectory() { + log_info "Cleaning $TARGET_DIRECTORY directory." + rm -rf "$TARGET_DIRECTORY" + + if [[ $? != 0 ]]; then + log_error "Failed to clean $TARGET_DIRECTORY directory" $? + exit 1 + fi +} + +createInstallationDirectory() { + if [ -d "${TARGET_DIRECTORY}" ]; then + deleteInstallationDirectory + fi + mkdir -pv "$TARGET_DIRECTORY" + + if [[ $? != 0 ]]; then + log_error "Failed to create $TARGET_DIRECTORY directory" $? + exit 1 + fi +} + +copyDarwinDirectory(){ + createInstallationDirectory + cp -r "$SCRIPTPATH/darwin" "${TARGET_DIRECTORY}/" + chmod -R 755 "${TARGET_DIRECTORY}/darwin/scripts" + chmod -R 755 "${TARGET_DIRECTORY}/darwin/Resources" + chmod 755 "${TARGET_DIRECTORY}/darwin/Distribution" +} + +copyBuildDirectory() { + sed -i '' -e 's/__PRODUCT__/'${PRODUCT}'/g' "${TARGET_DIRECTORY}/darwin/scripts/postinstall" + chmod -R 755 "${TARGET_DIRECTORY}/darwin/scripts/postinstall" + + sed -i '' -e 's/__PRODUCT__/'${PRODUCT}'/g' "${TARGET_DIRECTORY}/darwin/Distribution" + chmod -R 755 "${TARGET_DIRECTORY}/darwin/Distribution" + + sed -i '' -e 's/__PRODUCT__/'${PRODUCT}'/g' "${TARGET_DIRECTORY}"/darwin/Resources/*.html + chmod -R 755 "${TARGET_DIRECTORY}/darwin/Resources/" + + rm -rf "${TARGET_DIRECTORY}/darwinpkg" + mkdir -p "${TARGET_DIRECTORY}/darwinpkg" + + # Copy application files into correct directory structure + mkdir -p "${TARGET_DIRECTORY}/darwinpkg/${PRODUCT}" + cp -a "$SCRIPTPATH"/application/. "${TARGET_DIRECTORY}/darwinpkg/${PRODUCT}" + chmod -R 755 "${TARGET_DIRECTORY}/darwinpkg/${PRODUCT}" + + rm -rf "${TARGET_DIRECTORY}/package" + mkdir -p "${TARGET_DIRECTORY}/package" + chmod -R 755 "${TARGET_DIRECTORY}/package" + + rm -rf "${TARGET_DIRECTORY}/pkg" + mkdir -p "${TARGET_DIRECTORY}/pkg" + chmod -R 755 "${TARGET_DIRECTORY}/pkg" +} + +function buildPackage() { + log_info "Application installer package building started.(1/3)" + pkgbuild --identifier "org.${PRODUCT}" \ + --version "main" \ + --scripts "${TARGET_DIRECTORY}/darwin/scripts" \ + --root "${TARGET_DIRECTORY}/darwinpkg" \ + "${TARGET_DIRECTORY}/package/${PRODUCT}.pkg" > /dev/null 2>&1 +} + +function buildProduct() { + log_info "Application installer product building started.(2/3)" + productbuild --distribution "${TARGET_DIRECTORY}/darwin/Distribution" \ + --resources "${TARGET_DIRECTORY}/darwin/Resources" \ + --package-path "${TARGET_DIRECTORY}/package" \ + "${TARGET_DIRECTORY}/pkg/$1" > /dev/null 2>&1 +} + +function createInstaller() { + log_info "Application installer generation process started.(3 Steps)" + buildPackage + buildProduct ${PRODUCT}-macos-installer-x64.pkg + log_info "Application installer generation steps finished." +} + +function createUninstaller(){ + cp "$SCRIPTPATH/darwin/Resources/uninstall.sh" "${TARGET_DIRECTORY}/darwinpkg/${PRODUCT}" + sed -i '' -e "s/__PRODUCT__/${PRODUCT}/g" "${TARGET_DIRECTORY}/darwinpkg/${PRODUCT}/uninstall.sh" +} + +#Main script +log_info "Installer generating process started." + +copyDarwinDirectory +copyBuildDirectory +createUninstaller +createInstaller + +log_info "Installer generating process finished" +exit 0 diff --git a/build-scripts/macos/darwin/Distribution b/build-scripts/macos/darwin/Distribution new file mode 100755 index 0000000..67597f2 --- /dev/null +++ b/build-scripts/macos/darwin/Distribution @@ -0,0 +1,36 @@ + + + __PRODUCT__ + + + + + + + + + + + + + + + + __PRODUCT__.pkg + diff --git a/build-scripts/macos/darwin/Resources/LICENSE.txt b/build-scripts/macos/darwin/Resources/LICENSE.txt new file mode 100644 index 0000000..7c875d9 --- /dev/null +++ b/build-scripts/macos/darwin/Resources/LICENSE.txt @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2022 Chia Network + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/build-scripts/macos/darwin/Resources/banner.png b/build-scripts/macos/darwin/Resources/banner.png new file mode 100644 index 0000000..5d693fb Binary files /dev/null and b/build-scripts/macos/darwin/Resources/banner.png differ diff --git a/build-scripts/macos/darwin/Resources/conclusion.html b/build-scripts/macos/darwin/Resources/conclusion.html new file mode 100644 index 0000000..aecf599 --- /dev/null +++ b/build-scripts/macos/darwin/Resources/conclusion.html @@ -0,0 +1,20 @@ + + + + + + + +
+

Climate Portal

+

Thank you for installing Climate Portal.

+
+
+
+
Uninstall Climate Portal
+

Run the following command to uninstall Climate Portal.
+
  $ sudo bash ~/__PRODUCT__/uninstall.sh
+

+
+ + diff --git a/build-scripts/macos/darwin/Resources/uninstall.sh b/build-scripts/macos/darwin/Resources/uninstall.sh new file mode 100644 index 0000000..9e335c5 --- /dev/null +++ b/build-scripts/macos/darwin/Resources/uninstall.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +#Generate application uninstallers for macOS. + +#Parameters +DATE=`date +%Y-%m-%d` +TIME=`date +%H:%M:%S` +LOG_PREFIX="[$DATE $TIME]" + +#Functions +log_info() { + echo "${LOG_PREFIX}[INFO]" $1 +} + +log_warn() { + echo "${LOG_PREFIX}[WARN]" $1 +} + +log_error() { + echo "${LOG_PREFIX}[ERROR]" $1 +} + +#Check running user +if (( $EUID != 0 )); then + echo "Please run as root." + exit +fi + +echo "Welcome to Application Uninstaller" +echo "The following packages will be REMOVED:" +echo " __PRODUCT__" +while true; do + read -p "Do you wish to continue [Y/n]?" answer + [[ $answer == "y" || $answer == "Y" || $answer == "" ]] && break + [[ $answer == "n" || $answer == "N" ]] && exit 0 + echo "Please answer with 'y' or 'n'" +done + + +#Need to replace these with install preparation script +PRODUCT=__PRODUCT__ + +echo "Application uninstalling process started" +#forget from pkgutil +pkgutil --forget "org.$PRODUCT" > /dev/null 2>&1 +if [ $? -eq 0 ] +then + echo "[2/3] [DONE] Successfully deleted application information" +else + echo "[2/3] [ERROR] Could not delete application information" >&2 +fi + +#remove application source distribution +[ -e "${HOME}/${PRODUCT}" ] && rm -rf "${HOME}/${PRODUCT}" +if [ $? -eq 0 ] +then + echo "[3/3] [DONE] Successfully deleted application" +else + echo "[3/3] [ERROR] Could not delete application" >&2 +fi + +echo "Application uninstall process finished" +exit 0 diff --git a/build-scripts/macos/darwin/Resources/welcome.html b/build-scripts/macos/darwin/Resources/welcome.html new file mode 100644 index 0000000..8babb5a --- /dev/null +++ b/build-scripts/macos/darwin/Resources/welcome.html @@ -0,0 +1,14 @@ + + + + + + +
+
+

This will install Climate Portal on your computer. You will be guided through the steps necessary to install this software.

+
+

Click “Continue" to continue the setup

+
+ + diff --git a/build-scripts/macos/darwin/scripts/postinstall b/build-scripts/macos/darwin/scripts/postinstall new file mode 100755 index 0000000..b3d7665 --- /dev/null +++ b/build-scripts/macos/darwin/scripts/postinstall @@ -0,0 +1,13 @@ +#!/bin/bash + +#Parameters +PRODUCT_HOME="${HOME}/__PRODUCT__" + +echo "Post installation process started" + +#Change permissions in home directory +echo "Change permissions in product home" +cd "${PRODUCT_HOME}" || exit 1 +chmod -R 755 . + +echo "Post installation process finished" diff --git a/build-scripts/macos/entitlements.mac.plist b/build-scripts/macos/entitlements.mac.plist new file mode 100644 index 0000000..e56c5d8 --- /dev/null +++ b/build-scripts/macos/entitlements.mac.plist @@ -0,0 +1,10 @@ + + + + + com.apple.security.cs.allow-unsigned-executable-memory + + com.apple.security.cs.disable-library-validation + + + diff --git a/package.json b/package.json index cd1d7fa..999863f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "climate-portal", - "version": "1.0.0", + "version": "1.0.1", "bin": "./server.js", "description": "", "main": "proxy.js", diff --git a/server.js b/server.js index 73713cc..c02e34a 100644 --- a/server.js +++ b/server.js @@ -18,11 +18,10 @@ const warehouseApi = require("./warehouse"); const { updateConfig, getConfig } = require("./utils/config-loader"); const { connectToOrgSchema, tokenizeUnitSchema } = require("./validations.js"); const { getStoreIds } = require("./datalayer.js"); -const { unzipAndUnlockZipFile } = require("./utils/decompress"); const app = express(); const port = 31311; -const CONFIG = getConfig(); +let CONFIG = getConfig(); const headerKeys = Object.freeze({ ORG_UID: "x-org-uid", @@ -51,6 +50,28 @@ const updateQueryWithParam = (query, ...params) => { return `?${newParams}`; }; +app.post("/connect", validator.body(connectToOrgSchema), async (req, res) => { + const orgUid = req.body.orgUid; + try { + const storeIds = await getStoreIds(orgUid); + + if (storeIds.includes(orgUid)) { + updateConfig({ HOME_ORG: orgUid }); + setTimeout(() => { + CONFIG = getConfig(); + }, 0); + res.json({ message: "successfully connected" }); + } else { + throw new Error("orgUid not found"); + } + } catch (error) { + res.status(400).json({ + message: "Error connecting orgUid", + error: error.message, + }); + } +}); + app.use(async function (req, res, next) { try { if (CONFIG.HOME_ORG === null) { @@ -157,25 +178,6 @@ app.use( }) ); -app.post("/connect", validator.body(connectToOrgSchema), async (req, res) => { - const orgUid = req.body.orgUid; - try { - const storeIds = await getStoreIds(orgUid); - - if (storeIds.includes(orgUid)) { - updateConfig({ HOME_ORG: orgUid }); - res.json({ message: "successfully connected" }); - } else { - throw new Error("orgUid not found"); - } - } catch (error) { - res.status(400).json({ - message: "Error connecting orgUid", - error: error.message, - }); - } -}); - const updateUnitMarketplaceIdentifierWithAssetId = async ( warehouseUnitId, asset_id @@ -206,7 +208,7 @@ const confirmTokenRegistrationOnWarehouse = async ( if (retry <= 60) { try { await new Promise((resolve) => setTimeout(() => resolve(), 30000)); - + const thereAreNoPendingTransactions = await warehouseApi.getHasPendingTransactions(); @@ -240,7 +242,7 @@ const registerTokenCreationOnClimateWarehouse = async ( ) { const isTokenRegistered = await confirmTokenRegistrationOnWarehouse(); - if (isTokenRegistered) { + if (isTokenRegistered && CONFIG.UPDATE_CLIMATE_WAREHOUSE) { await updateUnitMarketplaceIdentifierWithAssetId( warehouseUnitId, token.asset_id @@ -305,7 +307,6 @@ app.post("/tokenize", validator.body(tokenizeUnitSchema), async (req, res) => { }, payment: { amount: (req.body.amount || 1) * 1000, - fee: 100, to_address: req.body.to_address, }, }), @@ -359,10 +360,7 @@ const sendParseDetokRequest = async (detokString) => { app.post("/parse-detok-file", async (req, res) => { try { - const password = req.body.password; - const filePath = req.files.file.path; - - let detokString = await unzipAndUnlockZipFile(filePath, password); + let detokString = req.body.detokString; detokString = detokString.replace(/(\r\n|\n|\r)/gm, ""); const detokStringkIsValid = typeof detokString === "string" && detokString.startsWith("detok"); @@ -402,6 +400,7 @@ app.post("/parse-detok-file", async (req, res) => { // public_key: orgMetaData, public_key: parsedAssetIdOrgMetaData?.public_key, asset_id: assetId, + warehouse_project_id: project.warehouseProjectId, }, content: detokString, unit: unitToBeDetokenized, @@ -419,7 +418,10 @@ app.post("/parse-detok-file", async (req, res) => { app.post("/confirm-detokanization", async (req, res) => { try { - const confirmDetokanizationBody = { ...req.body }; + const confirmDetokanizationBody = _.cloneDeep(req.body); + + console.log(confirmDetokanizationBody); + const assetId = confirmDetokanizationBody?.token?.asset_id; const warehouseUnitsToDetokenizeFrom = @@ -462,7 +464,7 @@ app.post("/confirm-detokanization", async (req, res) => { } const confirmDetokanizationResponse = await request({ - method: "post", + method: "put", url: `${CONFIG.TOKENIZE_DRIVER_HOST}/v1/tokens/${assetId}/detokenize`, body: JSON.stringify(confirmDetokanizationBody), headers: { "Content-Type": "application/json" }, diff --git a/utils/config-loader.js b/utils/config-loader.js index 47c0f12..d4182cd 100644 --- a/utils/config-loader.js +++ b/utils/config-loader.js @@ -9,7 +9,7 @@ const homeDir = os.homedir(); const persistanceFolderPath = `${homeDir}/.chia/climate-portal`; const configFilePath = path.resolve(`${persistanceFolderPath}/config.yaml`); -const getConfig = _.memoize(() => { +const getConfig = () => { try { if (!fs.existsSync(configFilePath)) { try { @@ -32,7 +32,7 @@ const getConfig = _.memoize(() => { } catch (e) { console.log(`Config file not found at ${configFilePath}`, e); } -}); +}; const updateConfig = (updates) => { try { diff --git a/utils/defaultConfig.json b/utils/defaultConfig.json index 9608209..2a8827e 100644 --- a/utils/defaultConfig.json +++ b/utils/defaultConfig.json @@ -2,5 +2,6 @@ "DATA_LAYER_HOST": "https://localhost:8562", "HOME_ORG": null, "REGISTRY_HOST": "http://localhost:31310", - "TOKENIZE_DRIVER_HOST": "http://127.0.0.1:31312" + "TOKENIZE_DRIVER_HOST": "http://127.0.0.1:31312", + "UPDATE_CLIMATE_WAREHOUSE": false }