New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

savim-googledrive

Package Overview
Dependencies
Maintainers
1
Versions
339
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

savim-googledrive - npm Package Compare versions

Comparing version 1.0.26 to 1.0.27

36

dist/savim-googledrive.cjs.development.js

@@ -376,2 +376,3 @@ 'use strict';

function replaceAll(str, match, replacement) {
console.log(str);
return str.replace(new RegExp(escapeRegExp(match), 'g'), function () {

@@ -431,7 +432,8 @@ return replacement;

var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(client, path) {
var foldersArray, fileName, folderId, _iterator2, _step2, folderName, folders, res, files;
var correctPath, foldersArray, fileName, folderId, _iterator2, _step2, folderName, folders, res, files;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
foldersArray = path.substring(1).split('/');
correctPath = path.startsWith('/') ? path : "/" + path;
foldersArray = correctPath.substring(1).split('/');
if (foldersArray.length !== 1) {

@@ -441,13 +443,13 @@ fileName = foldersArray[foldersArray.length - 1];

} else {
fileName = foldersArray;
fileName = foldersArray[0];
foldersArray = [];
}
_iterator2 = _createForOfIteratorHelperLoose(foldersArray);
case 3:
case 4:
if ((_step2 = _iterator2()).done) {
_context2.next = 13;
_context2.next = 14;
break;
}
folderName = _step2.value;
_context2.next = 7;
_context2.next = 8;
return client.files.list({

@@ -457,16 +459,16 @@ q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + replaceAll(folderName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"),

});
case 7:
case 8:
folders = _context2.sent;
if (!(!folders.data.files || folders.data.files.length === 0)) {
_context2.next = 10;
_context2.next = 11;
break;
}
throw new Error("Folder '" + folderName + "' not found");
case 10:
case 11:
folderId = folders.data.files[0].id;
case 11:
_context2.next = 3;
case 12:
_context2.next = 4;
break;
case 13:
_context2.next = 15;
case 14:
_context2.next = 16;
return client.files.list({

@@ -476,13 +478,13 @@ q: "trashed = false and name = '" + replaceAll(fileName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"),

});
case 15:
case 16:
res = _context2.sent;
files = res.data.files;
if (!(!files || files.length === 0)) {
_context2.next = 19;
_context2.next = 20;
break;
}
throw new Error("File '" + fileName + "' not found");
case 19:
case 20:
return _context2.abrupt("return", files[0].id);
case 20:
case 21:
case "end":

@@ -489,0 +491,0 @@ return _context2.stop();

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("googleapis");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new O(n||[]);return i(o,"_invoke",{value:k(t,r,a)}),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function d(){}function v(){}var y={};s(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==r&&n.call(m,a)&&(y=m);var w=v.prototype=h.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var r;i(this,"_invoke",{value:function(i,o){function a(){return new e((function(r,a){!function r(i,o,a,u){var c=f(t[i],t,o);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}})}function k(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var u=L(a,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=f(t,e,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=f(n,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,p;var o=i.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function _(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:F}}function F(){return{value:void 0,done:!0}}return d.prototype=v,i(w,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:d,configurable:!0}),d.displayName=s(v,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,s(t,c,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),s(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new b(l(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(w),s(w,c,"Generator"),s(w,a,(function(){return this})),s(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(u&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;j(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function r(t,e,r,n,i,o,a){try{var u=t[o](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,i)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(i,o){var a=t.apply(e,n);function u(t){r(a,i,o,u,c,"next",t)}function c(t){r(a,i,o,u,c,"throw",t)}u(void 0)}))}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(t,e,r){return t.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),(function(){return r}))}var u=function(){var t=n(e().mark((function t(r,n){var i,u,c,s,l,f;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=1!==(i=n.substring(1).split("/")).length?i.slice(0,-1):[],c=o(i);case 3:if((s=c()).done){t.next=13;break}return l=s.value,t.next=7,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+a(l,"'","'\"'\"'")+"'"+(u?" and '"+u+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 7:if((f=t.sent).data.files&&0!==f.data.files.length){t.next=10;break}throw new Error("Folder '"+l+"' not found");case 10:u=f.data.files[0].id;case 11:t.next=3;break;case 13:return t.abrupt("return",u);case 14:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),c=function(){var t=n(e().mark((function t(r,n){var i,u,c,s,l,f,p,h;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:1!==(i=n.substring(1).split("/")).length?(u=i[i.length-1],i=i.slice(0,-1)):(u=i,i=[]),s=o(i);case 3:if((l=s()).done){t.next=13;break}return f=l.value,t.next=7,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+a(f,"'","'\"'\"'")+"'"+(c?" and '"+c+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 7:if((p=t.sent).data.files&&0!==p.data.files.length){t.next=10;break}throw new Error("Folder '"+f+"' not found");case 10:c=p.data.files[0].id;case 11:t.next=3;break;case 13:return t.next=15,r.files.list({q:"trashed = false and name = '"+a(u,"'","'\"'\"'")+"'"+(c?" and '"+c+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 15:if((h=t.sent.data.files)&&0!==h.length){t.next=19;break}throw new Error("File '"+u+"' not found");case 19:return t.abrupt("return",h[0].id);case 20:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),s=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return 1!==(n=r.substring(1).split("/")).length?(i=n[n.length-1],n=n.slice(0,-1)):(i=n[0],n=[]),t.abrupt("return",i);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();function l(t){var e=[];return new Promise((function(r,n){t.on("data",(function(t){return e.push(Buffer.from(t))})),t.on("error",(function(t){return n(t)})),t.on("end",(function(){return r(Buffer.concat(e).toString("base64"))}))}))}exports.SavimGoogleDriveProvider=function(){function r(e){this.config=e,this.name="google-drive",this.client=t.google.drive({version:"v3",auth:e})}var i=r.prototype;return i.isHealthy=function(){var t=n(e().mark((function t(){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.drives.list();case 3:return t.abrupt("return",!0);case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",!1);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(){return t.apply(this,arguments)}}(),i.getFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.get({fileId:n,alt:"media",acknowledgeAbuse:!0},{responseType:"stream"});case 5:return t.abrupt("return",l(t.sent.data));case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.uploadFile=function(){var t=n(e().mark((function t(r,n,i){var o,a;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=3,s(r);case 3:return o=t.sent,t.next=6,u(this.client,r);case 6:return a=t.sent,t.next=9,this.client.files.create({requestBody:{name:o,parents:[a]},media:{body:n}});case 9:return t.abrupt("return",t.sent.data.id);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),i.deleteFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.createFolder=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(r);case 2:return n=t.sent,t.next=5,u(this.client,r);case 5:return i=t.sent,t.next=8,this.client.files.create({requestBody:{name:n,mimeType:"application/vnd.google-apps.folder",parents:i?[i]:[]},fields:"id, name"});case 8:return t.abrupt("return",t.sent.data.id);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.deleteFolder=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFolders=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,c(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFiles=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,c(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType != 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r}();
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("googleapis");function e(){e=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function l(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new O(n||[]);return i(o,"_invoke",{value:k(t,r,a)}),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var p={};function h(){}function d(){}function v(){}var y={};c(y,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(_([])));m&&m!==r&&n.call(m,a)&&(y=m);var w=v.prototype=h.prototype=Object.create(y);function x(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function b(t,e){var r;i(this,"_invoke",{value:function(i,o){function a(){return new e((function(r,a){!function r(i,o,a,u){var s=f(t[i],t,o);if("throw"!==s.type){var c=s.arg,l=c.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){c.value=t,a(c)}),(function(t){return r("throw",t,a,u)}))}u(s.arg)}(i,o,r,a)}))}return r=r?r.then(a,a):a()}})}function k(t,e,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return{value:void 0,done:!0}}for(r.method=i,r.arg=o;;){var a=r.delegate;if(a){var u=L(a,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=f(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===p)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}function L(t,e){var r=e.method,n=t.iterator[r];if(void 0===n)return e.delegate=null,"throw"===r&&t.iterator.return&&(e.method="return",e.arg=void 0,L(t,e),"throw"===e.method)||"return"!==r&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=f(n,t.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,p;var o=i.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function j(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function _(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,i=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:F}}function F(){return{value:void 0,done:!0}}return d.prototype=v,i(w,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:d,configurable:!0}),d.displayName=c(v,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,c(t,s,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},x(b.prototype),c(b.prototype,u,(function(){return this})),t.AsyncIterator=b,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var a=new b(l(e,r,n,i),o);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(w),c(w,s,"Generator"),c(w,a,(function(){return this})),c(w,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},t.values=_,O.prototype={constructor:O,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var u=n.call(o,"catchLoc"),s=n.call(o,"finallyLoc");if(u&&s){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),j(r),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var i=n.arg;j(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:_(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function r(t,e,r,n,i,o,a){try{var u=t[o](a),s=u.value}catch(t){return void r(t)}u.done?e(s):Promise.resolve(s).then(n,i)}function n(t){return function(){var e=this,n=arguments;return new Promise((function(i,o){var a=t.apply(e,n);function u(t){r(a,i,o,u,s,"next",t)}function s(t){r(a,i,o,u,s,"throw",t)}u(void 0)}))}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return i(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(t,e,r){return console.log(t),t.replace(new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g"),(function(){return r}))}var u=function(){var t=n(e().mark((function t(r,n){var i,u,s,c,l,f;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=1!==(i=n.substring(1).split("/")).length?i.slice(0,-1):[],s=o(i);case 3:if((c=s()).done){t.next=13;break}return l=c.value,t.next=7,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+a(l,"'","'\"'\"'")+"'"+(u?" and '"+u+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 7:if((f=t.sent).data.files&&0!==f.data.files.length){t.next=10;break}throw new Error("Folder '"+l+"' not found");case 10:u=f.data.files[0].id;case 11:t.next=3;break;case 13:return t.abrupt("return",u);case 14:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),s=function(){var t=n(e().mark((function t(r,n){var i,u,s,c,l,f,p,h,d;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=n.startsWith("/")?n:"/"+n,1!==(u=i.substring(1).split("/")).length?(s=u[u.length-1],u=u.slice(0,-1)):(s=u[0],u=[]),l=o(u);case 4:if((f=l()).done){t.next=14;break}return p=f.value,t.next=8,r.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '"+a(p,"'","'\"'\"'")+"'"+(c?" and '"+c+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 8:if((h=t.sent).data.files&&0!==h.data.files.length){t.next=11;break}throw new Error("Folder '"+p+"' not found");case 11:c=h.data.files[0].id;case 12:t.next=4;break;case 14:return t.next=16,r.files.list({q:"trashed = false and name = '"+a(s,"'","'\"'\"'")+"'"+(c?" and '"+c+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 16:if((d=t.sent.data.files)&&0!==d.length){t.next=20;break}throw new Error("File '"+s+"' not found");case 20:return t.abrupt("return",d[0].id);case 21:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}(),c=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return 1!==(n=r.substring(1).split("/")).length?(i=n[n.length-1],n=n.slice(0,-1)):(i=n[0],n=[]),t.abrupt("return",i);case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}();function l(t){var e=[];return new Promise((function(r,n){t.on("data",(function(t){return e.push(Buffer.from(t))})),t.on("error",(function(t){return n(t)})),t.on("end",(function(){return r(Buffer.concat(e).toString("base64"))}))}))}exports.SavimGoogleDriveProvider=function(){function r(e){this.config=e,this.name="google-drive",this.client=t.google.drive({version:"v3",auth:e})}var i=r.prototype;return i.isHealthy=function(){var t=n(e().mark((function t(){return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,this.client.drives.list();case 3:return t.abrupt("return",!0);case 6:return t.prev=6,t.t0=t.catch(0),t.abrupt("return",!1);case 9:case"end":return t.stop()}}),t,this,[[0,6]])})));return function(){return t.apply(this,arguments)}}(),i.getFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.get({fileId:n,alt:"media",acknowledgeAbuse:!0},{responseType:"stream"});case 5:return t.abrupt("return",l(t.sent.data));case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.uploadFile=function(){var t=n(e().mark((function t(r,n,i){var o,a;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=3,c(r);case 3:return o=t.sent,t.next=6,u(this.client,r);case 6:return a=t.sent,t.next=9,this.client.files.create({requestBody:{name:o,parents:[a]},media:{body:n}});case 9:return t.abrupt("return",t.sent.data.id);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),i.deleteFile=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.createFolder=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c(r);case 2:return n=t.sent,t.next=5,u(this.client,r);case 5:return i=t.sent,t.next=8,this.client.files.create({requestBody:{name:n,mimeType:"application/vnd.google-apps.folder",parents:i?[i]:[]},fields:"id, name"});case 8:return t.abrupt("return",t.sent.data.id);case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.deleteFolder=function(){var t=n(e().mark((function t(r){var n;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,s(this.client,r);case 2:return n=t.sent,t.next=5,this.client.files.delete({fileId:n});case 5:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFolders=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,s(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType = 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),i.getFiles=function(){var t=n(e().mark((function t(r){var n,i;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if("/"===r){t.next=4;break}return t.next=3,s(this.client,r);case 3:i=t.sent;case 4:return t.next=6,this.client.files.list({q:"mimeType != 'application/vnd.google-apps.folder' and trashed = false"+(i?" and '"+i+"' in parents":" and 'root' in parents"),fields:"files(id, name)"});case 6:return t.abrupt("return",null==(n=t.sent.data.files)?void 0:n.map((function(t){return("/"===r?"":r)+"/"+t.name})));case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r}();
//# sourceMappingURL=savim-googledrive.cjs.production.min.js.map

@@ -372,2 +372,3 @@ import { google } from 'googleapis';

function replaceAll(str, match, replacement) {
console.log(str);
return str.replace(new RegExp(escapeRegExp(match), 'g'), function () {

@@ -427,7 +428,8 @@ return replacement;

var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(client, path) {
var foldersArray, fileName, folderId, _iterator2, _step2, folderName, folders, res, files;
var correctPath, foldersArray, fileName, folderId, _iterator2, _step2, folderName, folders, res, files;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
foldersArray = path.substring(1).split('/');
correctPath = path.startsWith('/') ? path : "/" + path;
foldersArray = correctPath.substring(1).split('/');
if (foldersArray.length !== 1) {

@@ -437,13 +439,13 @@ fileName = foldersArray[foldersArray.length - 1];

} else {
fileName = foldersArray;
fileName = foldersArray[0];
foldersArray = [];
}
_iterator2 = _createForOfIteratorHelperLoose(foldersArray);
case 3:
case 4:
if ((_step2 = _iterator2()).done) {
_context2.next = 13;
_context2.next = 14;
break;
}
folderName = _step2.value;
_context2.next = 7;
_context2.next = 8;
return client.files.list({

@@ -453,16 +455,16 @@ q: "mimeType = 'application/vnd.google-apps.folder' and trashed = false and name = '" + replaceAll(folderName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"),

});
case 7:
case 8:
folders = _context2.sent;
if (!(!folders.data.files || folders.data.files.length === 0)) {
_context2.next = 10;
_context2.next = 11;
break;
}
throw new Error("Folder '" + folderName + "' not found");
case 10:
case 11:
folderId = folders.data.files[0].id;
case 11:
_context2.next = 3;
case 12:
_context2.next = 4;
break;
case 13:
_context2.next = 15;
case 14:
_context2.next = 16;
return client.files.list({

@@ -472,13 +474,13 @@ q: "trashed = false and name = '" + replaceAll(fileName, "'", "'\"'\"'") + "'" + (folderId ? " and '" + folderId + "' in parents" : " and 'root' in parents"),

});
case 15:
case 16:
res = _context2.sent;
files = res.data.files;
if (!(!files || files.length === 0)) {
_context2.next = 19;
_context2.next = 20;
break;
}
throw new Error("File '" + fileName + "' not found");
case 19:
case 20:
return _context2.abrupt("return", files[0].id);
case 20:
case 21:
case "end":

@@ -485,0 +487,0 @@ return _context2.stop();

{
"version": "1.0.26",
"version": "1.0.27",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -24,2 +24,3 @@ /* eslint-disable @typescript-eslint/ban-ts-comment */

function replaceAll(str: string, match: string, replacement: string) {
console.log(str);
return str.replace(new RegExp(escapeRegExp(match), 'g'), () => replacement);

@@ -66,3 +67,4 @@ }

const resolvePathToGetFileId = async (client: drive_v3.Drive, path: string) => {
let foldersArray = path.substring(1).split('/');
const correctPath = path.startsWith('/') ? path : `/${path}`;
let foldersArray = correctPath.substring(1).split('/');
let fileName;

@@ -74,3 +76,3 @@

} else {
fileName = foldersArray;
fileName = foldersArray[0];
foldersArray = [];

@@ -77,0 +79,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc