diff --git a/.github/workflows/build-push.yml b/.github/workflows/build-push.yml new file mode 100644 index 00000000..4cda0db6 --- /dev/null +++ b/.github/workflows/build-push.yml @@ -0,0 +1,74 @@ +name: Build and Push +on: push + +env: + NODE_VERSION: 18 + JAVA_VERSION: 11 + JAVA_DISTRIBUTION: 'adopt' + +jobs: + build-push: + name: run tests, build and push + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Node ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: ${{ env.JAVA_DISTRIBUTION }} + + - name: Install dependencies + run: npm run ci + + - name: Lint tests + run: npm run lint + + - name: Run tests + run: npm run test-report + + - name: Test Report + uses: dorny/test-reporter@v1 + if: always() + with: + name: Unit Tests + fail-on-error: true, + path: test-results.json # Path to test results + reporter: mocha-json # Format of test results + + - name: Publish Test Results + uses: EnricoMi/publish-unit-test-result-action@v2 + id: test-results + if: always() + with: + files: "test-results.json" + + - name: Run coverage + run: npm run cover + + - name: upload codecov + uses: codecov/codecov-action@v4 + + - name: Check whether we will be able to make the release + run: make release + + - name: AWS, credentials setup + if: ${{ github.ref == 'refs/heads/master' }} + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-region: us-west-1 + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + + - name: Deploy updated builds to staging + if: ${{ github.ref == 'refs/heads/master' }} + id: build + run: | + ./deployment/deploy-qa.sh \ No newline at end of file diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml deleted file mode 100644 index 063e7cf5..00000000 --- a/.github/workflows/deploy-qa.yml +++ /dev/null @@ -1,93 +0,0 @@ -name: Deploy QA -on: - pull_request: - types: [closed] - branches: - - main - paths-ignore: - - docs/** - - README.md -env: - BRANCH_NAME: '${{ github.event.inputs.branch_name || github.head_ref || github.ref_name }}' - NODE_VERSION: 18 - JAVA_VERSION: 11 - JAVA_DISTRIBUTION: 'adopt' - -jobs: - test-unit: - name: Unit tests - runs-on: [ ubuntu-latest ] - steps: - - name: Checkout ${{ github.ref_name }} - uses: actions/checkout@v4 - - - name: Install Node ${{ env.NODE_VERSION }} - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'npm' - - - name: Install dependencies - run: npm run ci - - - name: Run tests - id: runTests - run: npm run test - - - name: Run coverage - id: runCover - if: steps.runTests.outcome == 'success' - run: npm run cover - - - name : upload codecov - uses: codecov/codecov-action@v4 - if: steps.runCover.outcome == 'success' - - test-lint: - name: Lint - runs-on: [ ubuntu-latest ] - steps: - - name: Checkout ${{ github.ref_name }} - uses: actions/checkout@v4 - - - name: Install Node ${{ env.NODE_VERSION }} - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'npm' - - - name: Install dependencies - run: npm run ci - - - name: Lint tests - run: npm run lint - - deploy-qa: - name: Deploy-QA - needs: [test-unit,test-lint] - if: ${{ github.ref_name == 'main' && github.event.pull_request.merged == true }} - runs-on: [ ubuntu-latest ] - steps: - - name: Checkout ${{ github.ref_name }} - uses: actions/checkout@v4 - - - name: Install Node ${{ env.NODE_VERSION }} - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'npm' - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.JAVA_DISTRIBUTION }} - - - name: Install dependencies - run: npm run ci - - - name: Call the Build bash script for QA - id: build - run: bash ${GITHUB_WORKSPACE}/deployment/deploy-qa.sh - - - diff --git a/.github/workflows/gate-keep.yml b/.github/workflows/gate-keep.yml deleted file mode 100644 index 09fab731..00000000 --- a/.github/workflows/gate-keep.yml +++ /dev/null @@ -1,94 +0,0 @@ -name: Gate Keeping -on: - push: -env: - NODE_VERSION: 18 - JAVA_VERSION: 11 - JAVA_DISTRIBUTION: 'adopt' - -jobs: - test-unit: - name: Unit tests - runs-on: [ ubuntu-latest ] - steps: - - name: Checkout ${{ github.ref_name }} - uses: actions/checkout@v4 - - - name: Install Node ${{ env.NODE_VERSION }} - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'npm' - - - name: Install dependencies - run: npm run ci - - - name: Run tests - run: npm run test-report - - - name: Test Report - uses: dorny/test-reporter@v1 - if: success() || failure() - with: - name: Unit Tests - fail-on-error: true, - path: test-results.json # Path to test results - reporter: mocha-json # Format of test results - - - name: Publish Test Results - uses: EnricoMi/publish-unit-test-result-action@v2 - id: test-results - if: always() - with: - files: "test-results.json" - - - name: Run cover - run: npm run cover - - - name : upload codecov - uses: codecov/codecov-action@v4 - - test-lint: - name: Lint - runs-on: [ ubuntu-latest ] - steps: - - name: Checkout ${{ github.ref_name }} - uses: actions/checkout@v4 - - - name: Install Node ${{ env.NODE_VERSION }} - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'npm' - - - name: Install dependencies - run: npm run ci - - - name: Lint tests - run: npm run lint - - test-build: - name: Test-build - needs: [test-unit,test-lint] - runs-on: [ ubuntu-latest ] - steps: - - name: Checkout ${{ github.ref_name }} - uses: actions/checkout@v4 - - - name: Install Node ${{ env.NODE_VERSION }} - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'npm' - - name: Set up JDK 11 - uses: actions/setup-java@v4 - with: - java-version: ${{ env.JAVA_VERSION }} - distribution: ${{ env.JAVA_DISTRIBUTION }} - - - name: Install dependencies - run: npm run ci - - - name: Call the Build bash script for QA - run: bash ${GITHUB_WORKSPACE}/deployment/build-test.sh - diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index f11c53bb..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: demo -on: - workflow_dispatch: - inputs: - branch_name: - description: 'Name of the branch' - required: true - default: 'main' - - perform_deploy_qa: - description: 'Want to deploy to QA' - required: true - type: boolean - - perform_deploy_prod: - description: 'Want to deploy to Prod' - required: true - type: boolean - - version: - type: choice - description: Version for Prod release - options: - - major - - minor - - patch - push: - branches: - - main - - releases/** - paths-ignore: - - docs/** - - README.md - pull_request: - types: [opened, reopened, edited, closed] - branches: - - main - - releases/** - paths-ignore: - - docs/** - - README.md - -env: - BRANCH_NAME: '${{ github.event.inputs.branch_name || github.head_ref || github.ref_name }}' -jobs: - build: - runs-on: [small] - steps: - - name: Run tests - run: echo "Branch name is $BRANCH_NAME" - - name: Echo - run: | - echo "Version selected is, ${{ github.event.inputs.version }}!" - echo "- qa ${{ inputs.perform_deploy_qa }}!" diff --git a/.gitignore b/.gitignore index 305c9c75..d03d6314 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,6 @@ dev test-results.json .idea/ .direnv/ +dev.config +dev.html +example.html \ No newline at end of file diff --git a/Makefile b/Makefile index fcf1b7bf..65e8ce5b 100644 --- a/Makefile +++ b/Makefile @@ -31,24 +31,13 @@ ONPAGE_RELEASE=$(subst ",\",$(shell perl -pe 'BEGIN{$$sub="https://cdn.branch.io ONPAGE_DEV=$(subst ",\",$(shell perl -pe 'BEGIN{$$sub="build.js"};s\#SCRIPT_URL_HERE\#$$sub\#' src/onpage.js | $(CLOSURE_COMPILER) | node transform.js branch_sdk)) ONPAGE_TEST=$(subst ",\",$(shell perl -pe 'BEGIN{$$sub="../dist/build.js"};s\#SCRIPT_URL_HERE\#$$sub\#' src/onpage.js | $(CLOSURE_COMPILER) | node transform.js branch_sdk)) -# Check if the target being executed is "dev" and set COMPILER_DEV_ARGS if API_ENDPOINT argument has value -$(info Building dev...) -ifeq ($(MAKECMDGOALS),dev) - ifneq ($(API_ENDPOINT),) - COMPILER_DEV_ARGS := --define='DEFAULT_API_ENDPOINT=$(API_ENDPOINT)' - endif -endif - .PHONY: clean -all: dist/build.min.js dist/build.js example.html test/branch-deps.js test/integration-test.html +all: dist/build.min.js dist/build.js test/branch-deps.js test/integration-test.html clean: - rm -f dist/** docs/web/3_branch_web.md example.html test/branch-deps.js dist/build.min.js.gz test/integration-test.html + rm -f dist/** docs/web/3_branch_web.md test/branch-deps.js dist/build.min.js.gz test/integration-test.html release: clean all dist/build.min.js.gz @echo "released" -dev-clean: - rm -rf dev/* -dev: dev-clean dev-build example.html test/branch-deps.js: $(SOURCES) npx closure-make-deps \ @@ -71,21 +60,6 @@ dist/build.min.js.gz: dist/build.min.js mkdir -p dist && \ gzip -c dist/build.min.js > dist/build.min.js.gz -dev-build: $(SOURCES) $(EXTERN) - mkdir -p dev && \ - $(CLOSURE_COMPILER) $(COMPILER_ARGS) $(COMPILER_DEBUG_ARGS) $(COMPILER_DEV_ARGS) > dev/build.js - -example.html: src/web/example.template.html -ifeq ($(MAKECMDGOALS), release) - perl -pe 'BEGIN{$$a="$(ONPAGE_RELEASE)"}; s#// INSERT INIT CODE#$$a#' src/web/example.template.html > example.html -else ifeq ($(MAKECMDGOALS),dev) - perl -pe 'BEGIN{$$b="$(KEY_VALUE)"}; s#key_place_holder#$$b#' src/web/example.template.html > dev/example.template.html - perl -pe 'BEGIN{$$a="$(ONPAGE_DEV)"}; s#// INSERT INIT CODE#$$a#' dev/example.template.html > dev/example.html - rm -rf dev/example.template.html -else - perl -pe 'BEGIN{$$a="$(ONPAGE_DEV)"}; s#// INSERT INIT CODE#$$a#' src/web/example.template.html > example.html -endif - # Documentation docs/web/3_branch_web.md: $(SOURCES) diff --git a/README.md b/README.md index 0dc5dff2..4db2de13 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,8 @@ for full details. - [Testing] - [Troubleshooting] - [Web Full Reference] + +# Running locally +```sh +node startDev.js +``` \ No newline at end of file diff --git a/beta-release.sh b/beta-release.sh deleted file mode 100755 index 81d63cfc..00000000 --- a/beta-release.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -VERSION_NO_V=$(git rev-parse --short HEAD) -VERSION="v"$VERSION_NO_V -DATE=$(date "+%Y-%m-%d") - -echo "Deploying BETA version of Branch Web SDK: branch-beta-$VERSION" - -make release - -sed -i -e "s/branch-latest\.min\.js/branch-beta-$VERSION\.js/" example.html -sed -i -e "s/dist\/build\.min\.js/https\:\/\/cdn\.branch\.io\/branch-beta-$VERSION\.js/" event-example.html - -read -p "Copy to S3? " -n 1 -r -echo -if [[ $REPLY =~ ^[Yy]$ ]] -then - aws s3 cp --acl public-read --content-type="text/javascript" dist/build.min.js s3://branch-cdn/branch-beta-$VERSION.js - aws s3 cp --acl public-read example.html s3://branch-cdn/example-beta-$VERSION.html - aws s3 cp --acl public-read event-example.html s3://branch-cdn/event-example-beta-$VERSION.html -fi - -sed -i -e "s/branch-beta-$VERSION\.js/branch-latest\.min\.js/" example.html -sed -i -e "s/https\:\/\/cdn\.branch\.io\/branch-beta-$VERSION\.js/dist\/build\.min\.js/" event-example.html - -rm -f dist/build.min.js.gz - -echo -echo -echo -echo - -echo "Beta builds have been deployed:" -echo "https://cdn.branch.io/branch-beta-$VERSION.js" -echo "http://cdn.branch.io/example-beta-$VERSION.html" -echo "http://cdn.branch.io/event-example-beta-$VERSION.html" - -echo diff --git a/deployment/build-example-html.sh b/deployment/build-example-html.sh new file mode 100755 index 00000000..97fb1b12 --- /dev/null +++ b/deployment/build-example-html.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# This script takes the example.template.html and outputs the example.html +# based on the api key, the desired api, and the desired sdk build file + +# Used to publish to s3 for example files + +templateFile="examples/example.template.html" +outputFile="example.html" +tempFile="temp.html" # Temporary file for edits + +if [[ $# -ne 3 ]]; then + echo "Usage: $0 " + exit 1 +fi + +key_replacement="$1" +api_replacement="$2" +script_replacement="$3" + +key_placeholder="key_place_holder" +api_placeholder="api_place_holder" +script_placeholder="script_place_holder" + +if [[ ! -f "$templateFile" ]]; then + echo "Template file $templateFile does not exist." + exit 1 +fi + +cp "$templateFile" "$tempFile" +echo "Copied $templateFile to $tempFile" + +sed -e "s|$key_placeholder|$key_replacement|g" \ + -e "s|$api_placeholder|$api_replacement|g" \ + -e "s|$script_placeholder|$script_replacement|g" \ + "$tempFile" > "$outputFile" + +rm "$tempFile" +echo "Placeholders replaced successfully in $outputFile" diff --git a/deployment/deploy-qa.sh b/deployment/deploy-qa.sh index f1131d25..29094911 100644 --- a/deployment/deploy-qa.sh +++ b/deployment/deploy-qa.sh @@ -20,12 +20,16 @@ NC='\033[0m' echo -en "${GREEN}Pushing to builds ...${NC}\n" aws s3 cp --content-type="text/javascript" --content-encoding="gzip" dist/build.min.js.gz s3://branch-builds/web-sdk/branch-latest.min.js aws s3 cp --content-type="text/javascript" dist/build.js s3://branch-builds/web-sdk/branch.js + + ./deployment/build-example-html.sh "key_live_feebgAAhbH9Tv85H5wLQhpdaefiZv5Dv" "https://api.stage.branch.io" "https://cdn.branch.io/branch-staging-latest.min.js" + aws s3 cp example.html s3://branch-cdn/example-staging.html + + ./deployment/build-example-html.sh "key_live_hcnegAumkH7Kv18M8AOHhfgiohpXq5tB" "https://api2.branch.io" "https://cdn.branch.io/branch-latest.min.js" aws s3 cp example.html s3://branch-builds/web-sdk/example.html echo -en "${GREEN}Pushing to CDN ...${NC}\n" aws s3 cp --content-type="text/javascript" --content-encoding="gzip" dist/build.min.js.gz s3://branch-cdn/branch-staging-latest.min.js --cache-control "max-age=300" - aws s3 cp dist/example.html s3://branch-cdn/example-staging.html - + echo -en "Invalidating cloudfront distribution for staging ...\n" aws configure set preview.cloudfront true aws cloudfront create-invalidation --distribution-id E10P37NG0GMER --paths /branch-staging-latest.min.js /example-staging diff --git a/dev.config b/dev.config deleted file mode 100644 index 7bb591ad..00000000 --- a/dev.config +++ /dev/null @@ -1,5 +0,0 @@ -{ - "APIEndpoint": "https://api2.branch.io", - "sdkKey": null, - "port": "3000" -} \ No newline at end of file diff --git a/dist/build.js b/dist/build.js index 5462c797..5c36b5a9 100644 --- a/dist/build.js +++ b/dist/build.js @@ -3111,7 +3111,7 @@ Branch.prototype.qrCode = wrap(callback_params.CALLBACK_ERR_DATA, function(a, b, } e || (g.rawBuffer = f, g.base64 = function() { if (this.rawBuffer) { - const h = Array.from(new Uint8Array(this.rawBuffer)).map(k => String.fromCharCode(k)).join(""); + const h = Array.from(new Uint8Array(f)).map(k => String.fromCharCode(k)).join(""); return btoa(h); } throw Error("QrCode.rawBuffer is empty."); diff --git a/dist/build.min.js b/dist/build.min.js index f59fd8c4..b841f4f0 100644 --- a/dist/build.min.js +++ b/dist/build.min.js @@ -138,7 +138,7 @@ a,b,this.g,function(e,f){c(e,f)})};function W(a,b){var c=N(a.g);if(c=c&&c.referr Z.prototype.init=X(2,function(a,b,c){function d(){if("undefined"!==typeof document.hidden){var n="hidden";var r="visibilitychange"}else"undefined"!==typeof document.mozHidden?(n="mozHidden",r="mozvisibilitychange"):"undefined"!==typeof document.msHidden?(n="msHidden",r="msvisibilitychange"):"undefined"!==typeof document.webkitHidden&&(n="webkitHidden",r="webkitvisibilitychange");r&&!g.la&&(g.la=!0,document.addEventListener(r,function(){document[n]||(m(null),"function"===typeof g.G&&g.G())},!1))}function e(n, r){r&&(r=k(r),z||(r=f(r),Fa(g.g,r,p)),g.A=3,r.data_parsed=r.data&&0!==r.data.length?v(r.data):{});if(n)return g.A=2,g.B||(g.B=1,g.D=n.message),a(n,r&&Ga(r));try{a(n,r&&Ga(r))}catch(E){}finally{g.renderFinalize()}n=gb();(r=I(c.metadata,"object")?c.metadata:null)&&(r=ob(n.hosted_deeplink_data,r))&&0String.fromCharCode(k)).join("");return btoa(m)}throw Error("QrCode.rawBuffer is empty.");});return a(d||null,f||null)})}); +function(f){return a(f||null)})});Z.prototype.link=X(2,function(a,b){var c=Ja(b),d=this.o;this.j(wb,c,function(e,f){if(e)return a(e,Ca(d,c));a(null,f&&f.url)})});Z.prototype.qrCode=X(2,function(a,b,c){Ja(b).qr_code_settings=w(kb(c||{}));this.j(xb,Ja(b),function(d,e){function f(){}d||(f.rawBuffer=e,f.base64=function(){if(this.rawBuffer){const m=Array.from(new Uint8Array(e)).map(k=>String.fromCharCode(k)).join("");return btoa(m)}throw Error("QrCode.rawBuffer is empty.");});return a(d||null,f||null)})}); Z.prototype.deepview=X(1,function(a,b,c){var d=this;c||(c={});c.deepview_type="undefined"===typeof c.deepview_type?"deepview":"banner";b.data=D(Za(),b.data);b=B()?D({is_iframe:!0},b):b;b=Ja(b);var e=Ca(this.o,b);if(c.open_app||null===c.open_app||"undefined"===typeof c.open_app)b.open_app=!0;b.append_deeplink_path=!!c.append_deeplink_path;b.deepview_type=c.deepview_type;var f=W(d);f&&!c.make_new_link&&(b.link_click_id=Ka(f));b.banner_options=c;c.auto_branchify&&(b.auto_branchify=!0);d.G=ha(this.j, d,yb,b,function(m,k){if(m)return z||(d.F=function(){window.top.location=e}),a(m);"function"===typeof k&&(d.F=k);a(null)});d.G()}); Z.prototype.deepviewCta=X(1,function(a){if("undefined"===typeof this.F)return z?a(Error("Requested operation cannot be completed since tracking is disabled"),null):a(Error("Cannot call Deepview CTA, please call branch.deepview() first"),null);window.event&&(window.event.preventDefault?window.event.preventDefault():window.event.returnValue=!1);O(this,"didDeepviewCTA");this.F();a()}); diff --git a/example.html b/example.html deleted file mode 100644 index dbb4c540..00000000 --- a/example.html +++ /dev/null @@ -1,322 +0,0 @@ - - - - - - - - - Branch Metrics Web SDK Example App - - - - - -
-
-

Branch Metrics Web SDK Example

-
-
-
-

Session Info

-
Reading session from .init()...
-
-

Request

-
Click a button!
-
-

Response

-
Click a button!
-
-
-
-
-

Methods

-
-

Session and Identity

-
- - - - - - -
-
-
-

Sharing and Tracking

-
- - - - - -
-
-
-

QR Code

-
- -
-
-
-
-
-
- - - - - - - diff --git a/event-example.html b/examples/event-example.html similarity index 100% rename from event-example.html rename to examples/event-example.html diff --git a/event-v2-example.html b/examples/event-v2-example.html similarity index 100% rename from event-v2-example.html rename to examples/event-v2-example.html diff --git a/example-deepview.html b/examples/example-deepview.html similarity index 100% rename from example-deepview.html rename to examples/example-deepview.html diff --git a/src/web/example.template.html b/examples/example.template.html similarity index 93% rename from src/web/example.template.html rename to examples/example.template.html index a6d849d0..34fe4c29 100644 --- a/src/web/example.template.html +++ b/examples/example.template.html @@ -82,7 +82,8 @@

QR Code