diff --git a/README.md b/README.md index d100d79..3780486 100644 --- a/README.md +++ b/README.md @@ -71,11 +71,7 @@ vta.url("...").openDrawer() #### Drawer -TODO - -#### Embedded - -TODO +This is the default mode, VT Augment will be shown in a right side panel. # API @@ -130,15 +126,6 @@ vtaugment(container).closeDrawer() ``` -#### listen(event: string, callback: any) - -Not implemented yet. - -```js -vtaugment(container).listen("...", callback) - -``` - #### loading(active: boolean) The loading state is managed internally by the library but in the case of need the api provides this method to control loading manually. (Active loading hide the content) @@ -150,4 +137,8 @@ vtaugment(container).loading(true) ## Options -TODO +```js +{ + background: '#fff', // Background color for loading states +} +``` diff --git a/deploy.js b/deploy.js deleted file mode 100644 index ad1d9bc..0000000 --- a/deploy.js +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2019 Google LLC -// -// 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. - -'use strict'; - -const argv = require('minimist')(process.argv.slice(2)); -const pjson = require('./package.json'); - -async function main(bucketName, bucketPrefix, directoryPath) { - // [START upload_directory] - // Imports the Google Cloud client library - const {Storage} = require('@google-cloud/storage'); - const fs = require('fs'); - const path = require('path'); - const fileList = []; - - async function uploadDirectory() { - // Creates a client - const storage = new Storage(); - - // get the list of files from the specified directory - let dirCtr = 1; - let itemCtr = 0; - const pathDirName = path.dirname(directoryPath); - - getFiles(directoryPath); - - function getFiles(directory) { - fs.readdir(directory, (err, items) => { - dirCtr--; - itemCtr += items.length; - items.forEach(item => { - const fullPath = path.join(directory, item); - fs.stat(fullPath, (err, stat) => { - itemCtr--; - if (stat.isFile()) { - fileList.push(fullPath); - } else if (stat.isDirectory()) { - dirCtr++; - getFiles(fullPath); - } - if (dirCtr === 0 && itemCtr === 0) { - onComplete(); - } - }); - }); - }); - } - - async function onComplete() { - const resp = await Promise.all( - fileList.map(filePath => { - let destination = path.relative(pathDirName, filePath); - destination = bucketPrefix + destination.replace('dist/', ''); - - return storage - .bucket(bucketName) - .upload(filePath, {destination: destination}) - .then( - uploadResp => { - console.log(uploadResp[0]); - return {fileName: destination, status: uploadResp[0]}; - }, - err => { - console.error(err); - return {fileName: destination, response: err}; - } - ); - }) - ); - - const successfulUploads = - fileList.length - resp.filter(r => r.status instanceof Error).length; - console.log( - `${successfulUploads} files uploaded to ${bucketName} successfully.` - ); - } - } - - uploadDirectory().catch(console.error); - // [END upload_directory] -} - -function getBucketPrefix() { - let prefix = 'dev'; - - if (argv.v) { - prefix = argv.v; - } else if (argv.p) { - prefix = pjson.version; - } - - return prefix + '/'; -} - -main('vtaugment', getBucketPrefix(), 'dist').catch(console.error); diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..65a8945 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,28 @@ +FOLDER_PATH="dist" +BUCKET="vtaugment" +BUCKET_FOLDER="dev" +PACKAGE_VERSION=$(cat package.json \ + | grep version \ + | head -1 \ + | awk -F: '{ print $2 }' \ + | sed 's/[",]//g' \ + | tr -d '[[:space:]]') + +# Get arguments +while getopts "nv:p" opt; do + case $opt in + v) + BUCKET_FOLDER=$OPTARG + ;; + p) + BUCKET_FOLDER=$PACKAGE_VERSION + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + esac +done + +# Upload to the bucket with no cache +gsutil -m -h "Cache-Control:no-cache" cp -r ./$FOLDER_PATH/* gs://$BUCKET/$BUCKET_FOLDER/ diff --git a/dist/vt-augment.min.js b/dist/vt-augment.min.js index f5310c7..7151246 100644 --- a/dist/vt-augment.min.js +++ b/dist/vt-augment.min.js @@ -13,488 +13,386 @@ Copyright The Closure Library Authors. SPDX-License-Identifier: Apache-2.0 */ -var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.createTemplateTagFirstArg=function(a){return a.raw=a};$jscomp.createTemplateTagFirstArgWithRaw=function(a,b){a.raw=b;return a};$jscomp.checkStringArgs=function(a,b,c){if(null==a)throw new TypeError("The 'this' value for String.prototype."+c+" must not be null or undefined");if(b instanceof RegExp)throw new TypeError("First argument to String.prototype."+c+" must not be a regular expression");return a+""};$jscomp.ASSUME_ES5=!1; -$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.FORCE_POLYFILL_PROMISE=!1;$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,b,c){if(a==Array.prototype||a==Object.prototype)return a;a[b]=c.value;return a}; -$jscomp.getGlobal=function(a){a=["object"==typeof globalThis&&globalThis,a,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var b=0;b=e}},"es6","es3"); -$jscomp.findInternal=function(a,b,c){a instanceof String&&(a=String(a));for(var d=a.length,e=0;e=f}},"es6","es3"); -$jscomp.polyfill("String.prototype.repeat",function(a){return a?a:function(b){var c=$jscomp.checkStringArgs(this,null,"repeat");if(0>b||1342177279>>=1)c+=c;return d}},"es6","es3");$jscomp.polyfill("String.prototype.trimLeft",function(a){function b(){return this.replace(/^[\s\xa0]+/,"")}return a||b},"es_2019","es3");var COMPILED=!0,goog=goog||{};goog.global=this||self; -goog.exportPath_=function(a,b,c,d){a=a.split(".");d=d||goog.global;a[0]in d||"undefined"==typeof d.execScript||d.execScript("var "+a[0]);for(var e;a.length&&(e=a.shift());)if(a.length||void 0===b)d=d[e]&&d[e]!==Object.prototype[e]?d[e]:d[e]={};else if(!c&&goog.isObject(b)&&goog.isObject(d[e]))for(var f in b)b.hasOwnProperty(f)&&(d[e][f]=b[f]);else d[e]=b}; -goog.define=function(a,b){if(!COMPILED){var c=goog.global.CLOSURE_UNCOMPILED_DEFINES,d=goog.global.CLOSURE_DEFINES;c&&void 0===c.nodeType&&Object.prototype.hasOwnProperty.call(c,a)?b=c[a]:d&&void 0===d.nodeType&&Object.prototype.hasOwnProperty.call(d,a)&&(b=d[a])}return b};goog.FEATURESET_YEAR=2012;goog.DEBUG=!0;goog.LOCALE="en";goog.TRUSTED_SITE=!0;goog.DISALLOW_TEST_ONLY_CODE=COMPILED&&!goog.DEBUG;goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING=!1; -goog.provide=function(a){if(goog.isInModuleLoader_())throw Error("goog.provide cannot be used within a module.");if(!COMPILED&&goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');goog.constructNamespace_(a)};goog.constructNamespace_=function(a,b,c){if(!COMPILED){delete goog.implicitNamespaces_[a];for(var d=a;(d=d.substring(0,d.lastIndexOf(".")))&&!goog.getObjectByName(d);)goog.implicitNamespaces_[d]=!0}goog.exportPath_(a,b,c)}; -goog.getScriptNonce=function(a){if(a&&a!=goog.global)return goog.getScriptNonce_(a.document);null===goog.cspNonce_&&(goog.cspNonce_=goog.getScriptNonce_(goog.global.document));return goog.cspNonce_};goog.NONCE_PATTERN_=/^[\w+/_-]+[=]{0,2}$/;goog.cspNonce_=null;goog.getScriptNonce_=function(a){return(a=a.querySelector&&a.querySelector("script[nonce]"))&&(a=a.nonce||a.getAttribute("nonce"))&&goog.NONCE_PATTERN_.test(a)?a:""};goog.VALID_MODULE_RE_=/^[a-zA-Z_$][a-zA-Z0-9._$]*$/; -goog.module=function(a){if("string"!==typeof a||!a||-1==a.search(goog.VALID_MODULE_RE_))throw Error("Invalid module identifier");if(!goog.isInGoogModuleLoader_())throw Error("Module "+a+" has been loaded incorrectly. Note, modules cannot be loaded as normal scripts. They require some kind of pre-processing step. You're likely trying to load a module via a script tag or as a part of a concatenated bundle without rewriting the module. For more info see: https://github.com/google/closure-library/wiki/goog.module:-an-ES6-module-like-alternative-to-goog.provide."); -if(goog.moduleLoaderState_.moduleName)throw Error("goog.module may only be called once per module.");goog.moduleLoaderState_.moduleName=a;if(!COMPILED){if(goog.isProvided_(a))throw Error('Namespace "'+a+'" already declared.');delete goog.implicitNamespaces_[a]}};goog.module.get=function(a){return goog.module.getInternal_(a)}; -goog.module.getInternal_=function(a){if(!COMPILED){if(a in goog.loadedModules_)return goog.loadedModules_[a].exports;if(!goog.implicitNamespaces_[a])return a=goog.getObjectByName(a),null!=a?a:null}return null};goog.ModuleType={ES6:"es6",GOOG:"goog"};goog.moduleLoaderState_=null;goog.isInModuleLoader_=function(){return goog.isInGoogModuleLoader_()||goog.isInEs6ModuleLoader_()};goog.isInGoogModuleLoader_=function(){return!!goog.moduleLoaderState_&&goog.moduleLoaderState_.type==goog.ModuleType.GOOG}; -goog.isInEs6ModuleLoader_=function(){if(goog.moduleLoaderState_&&goog.moduleLoaderState_.type==goog.ModuleType.ES6)return!0;var a=goog.global.$jscomp;return a?"function"!=typeof a.getCurrentModulePath?!1:!!a.getCurrentModulePath():!1}; -goog.module.declareLegacyNamespace=function(){if(!COMPILED&&!goog.isInGoogModuleLoader_())throw Error("goog.module.declareLegacyNamespace must be called from within a goog.module");if(!COMPILED&&!goog.moduleLoaderState_.moduleName)throw Error("goog.module must be called prior to goog.module.declareLegacyNamespace.");goog.moduleLoaderState_.declareLegacyNamespace=!0}; -goog.declareModuleId=function(a){if(!COMPILED){if(!goog.isInEs6ModuleLoader_())throw Error("goog.declareModuleId may only be called from within an ES6 module");if(goog.moduleLoaderState_&&goog.moduleLoaderState_.moduleName)throw Error("goog.declareModuleId may only be called once per module.");if(a in goog.loadedModules_)throw Error('Module with namespace "'+a+'" already exists.');}if(goog.moduleLoaderState_)goog.moduleLoaderState_.moduleName=a;else{var b=goog.global.$jscomp;if(!b||"function"!=typeof b.getCurrentModulePath)throw Error('Module with namespace "'+ -a+'" has been loaded incorrectly.');b=b.require(b.getCurrentModulePath());goog.loadedModules_[a]={exports:b,type:goog.ModuleType.ES6,moduleId:a}}};goog.setTestOnly=function(a){if(goog.DISALLOW_TEST_ONLY_CODE)throw a=a||"",Error("Importing test-only code into non-debug environment"+(a?": "+a:"."));};goog.forwardDeclare=function(a){};COMPILED||(goog.isProvided_=function(a){return a in goog.loadedModules_||!goog.implicitNamespaces_[a]&&null!=goog.getObjectByName(a)},goog.implicitNamespaces_={"goog.module":!0}); -goog.getObjectByName=function(a,b){a=a.split(".");b=b||goog.global;for(var c=0;c>>0); -goog.uidCounter_=0;goog.cloneObject=function(a){var b=goog.typeOf(a);if("object"==b||"array"==b){if("function"===typeof a.clone)return a.clone();b="array"==b?[]:{};for(var c in a)b[c]=goog.cloneObject(a[c]);return b}return a};goog.bindNative_=function(a,b,c){return a.call.apply(a.bind,arguments)}; -goog.bindJs_=function(a,b,c){if(!a)throw Error();if(2").replace(/'/g,"'").replace(/"/g,'"').replace(/&/g,"&"));b&&(a=a.replace(/\{\$([^}]+)}/g,function(d,e){return null!=b&&e in b?b[e]:d}));return a}; -goog.getMsgWithFallback=function(a,b){return a};goog.exportSymbol=function(a,b,c){goog.exportPath_(a,b,!0,c)};goog.exportProperty=function(a,b,c){a[b]=c};goog.inherits=function(a,b){function c(){}c.prototype=b.prototype;a.superClass_=b.prototype;a.prototype=new c;a.prototype.constructor=a;a.base=function(d,e,f){for(var g=Array(arguments.length-2),h=2;h{"use strict";class X{constructor(){if(new.target!=String)throw 1;this.x=42}}let q=Reflect.construct(X,[],String);if(q.x!=42||!(q instanceof String))throw 1;for(const a of[2,3]){if(a==2)continue;function f(z={a}){let a=0;return z.a}{function f(){return 0;}}return f()==3}})()')}); -a("es7",function(){return b("2**3==8")});a("es8",function(){return b("async()=>1,1")});a("es9",function(){return b("({...rest}={}),1")});a("es_2019",function(){return b('let r;try{throw 0}catch{r="\u2029"};r')});a("es_2020",function(){return b("null?.x??1")});a("es_next",function(){return!1});return{target:c,map:d}},goog.Transpiler.prototype.needsTranspile=function(a,b){if("always"==goog.TRANSPILE)return!0;if("never"==goog.TRANSPILE)return!1;if(!this.requiresTranspilation_){var c=this.createRequiresTranspilation_(); -this.requiresTranspilation_=c.map;this.transpilationTarget_=this.transpilationTarget_||c.target}if(a in this.requiresTranspilation_)return this.requiresTranspilation_[a]?!0:!goog.inHtmlDocument_()||"es6"!=b||"noModule"in goog.global.document.createElement("script")?!1:!0;throw Error("Unknown language mode: "+a);},goog.Transpiler.prototype.transpile=function(a,b){return goog.transpile_(a,b,this.transpilationTarget_)},goog.transpiler_=new goog.Transpiler,goog.protectScriptTag_=function(a){return a.replace(/<\/(SCRIPT)/ig, -"\\x3c/$1")},goog.DebugLoader_=function(){this.dependencies_={};this.idToPath_={};this.written_={};this.loadingDeps_=[];this.depsToLoad_=[];this.paused_=!1;this.factory_=new goog.DependencyFactory(goog.transpiler_);this.deferredCallbacks_={};this.deferredQueue_=[]},goog.DebugLoader_.prototype.bootstrap=function(a,b){function c(){d&&(goog.global.setTimeout(d,0),d=null)}var d=b;if(a.length){b=[];for(var e=0;e\x3c/script>';f+="";f=goog.Dependency.defer_?f+("document.getElementById('script-"+e+"').onload = function() {\n goog.Dependency.callback_('"+e+"', this);\n};\n"):f+("goog.Dependency.callback_('"+e+"', document.getElementById('script-"+e+"'));");f+="\x3c/script>";b.write(goog.TRUSTED_TYPES_POLICY_?goog.TRUSTED_TYPES_POLICY_.createHTML(f):f)}else{var g=b.createElement("script");g.defer=goog.Dependency.defer_; -g.async=!1;c&&(g.nonce=c);goog.DebugLoader_.IS_OLD_IE_?(a.pause(),g.onreadystatechange=function(){if("loaded"==g.readyState||"complete"==g.readyState)a.loaded(),a.resume()}):g.onload=function(){g.onload=null;a.loaded()};g.src=goog.TRUSTED_TYPES_POLICY_?goog.TRUSTED_TYPES_POLICY_.createScriptURL(this.path):this.path;b.head.appendChild(g)}}else goog.logToConsole_("Cannot use default debug loader outside of HTML documents."),"deps.js"==this.relativePath?(goog.logToConsole_("Consider setting CLOSURE_IMPORT_SCRIPT before loading base.js, or setting CLOSURE_NO_DEPS to true."), -a.loaded()):a.pause()},goog.Es6ModuleDependency=function(a,b,c,d,e){goog.Dependency.call(this,a,b,c,d,e)},goog.inherits(goog.Es6ModuleDependency,goog.Dependency),goog.Es6ModuleDependency.prototype.load=function(a){function b(l,n){var m="",p=goog.getScriptNonce();p&&(m=' nonce="'+p+'"');l=n?' diff --git a/package.json b/package.json index d8b5a92..2ff92cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@virustotal/vt-augment", - "version": "1.4.0", + "version": "1.4.1", "description": "Client library that wraps common patterns when interact with the Virustotal Augment product", "keywords": [ "virustotal", @@ -16,7 +16,8 @@ "url": "https://github.com/VirusTotal/vt-augment/issues" }, "scripts": { - "build": "gulp" + "build": "gulp && npm run size", + "size": "ls -hl dist/ | awk 'FNR == 2 {print $5}'" }, "author": "", "license": "", diff --git a/src/vt-augment.js b/src/vt-augment.js index 2df785b..7c37dd1 100644 --- a/src/vt-augment.js +++ b/src/vt-augment.js @@ -109,12 +109,12 @@ class VTAugment { constructor(container, options) { this.container = container; this.options = options || {}; - this.isSrcdocSupported = !!("srcdoc" in document.createElement("iframe")) + this.isSrcdocSupported = !!('srcdoc' in document.createElement('iframe')) && SafeHtml.canUseSandboxIframe(); this.createStyleSheet_(); - this.container.classList.add(`vt-augment`); + this.container.classList.add('vt-augment'); if (this.options.background) { this.container.style.background = this.options.background; @@ -221,15 +221,6 @@ class VTAugment { return this; } - /** - * @public - * @return {!VTAugment} - */ - listen() { - console.error('listen: Not implemented yet'); - return this; - } - /** * @private * @param {boolean} active @@ -293,7 +284,7 @@ class VTAugment { setInnerHtml(temp, sandboxedIframe); temp.firstChild.setAttribute( - 'sandbox', 'allow-scripts allow-same-origin'); + 'sandbox', 'allow-scripts allow-same-origin allow-popups'); container.appendChild(temp.removeChild(temp.firstChild)); } @@ -324,17 +315,18 @@ class VTAugment { getHtmlAjax_(url) { const xmlhr = new XMLHttpRequest(); - xmlhr.onreadystatechange = function () { + xmlhr.onreadystatechange = () => { if (xmlhr.readyState === XMLHttpRequest.DONE) { if (xmlhr.status === 200) { lscache.set(url, xmlhr.response, 60); + this.loading_(false); } else { lscache.remove(url); } } }; - xmlhr.open("GET", url, true); + xmlhr.open('GET', url, true); xmlhr.send(); } @@ -352,6 +344,9 @@ class VTAugment { case 'VTAUGMENT:CLOSE': this.closeDrawer(); break; + case 'VTAUGMENT:CLEAR_CACHE': + lscache.flush(); + break; default: } } diff --git a/umd-wrapper.js b/umd-wrapper.js index 7f22cad..8529624 100644 --- a/umd-wrapper.js +++ b/umd-wrapper.js @@ -9,5 +9,5 @@ } }(this, function () { %output% - return module$exports$vtaugment.VTAugment; + return Z.VTAugment; }.bind(this)));