@gzhangx/googleapi 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +4 -2
- package/pub.bat +0 -2
- package/src/googleApi.ts +0 -296
- package/src/index.ts +0 -3
- package/test.bat +0 -2
- package/tsconfig.json +0 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"program":{"fileNames":["../node_modules/typescript/lib/lib.d.ts","../node_modules/typescript/lib/lib.es5.d.ts","../node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/typescript/lib/lib.dom.d.ts","../node_modules/typescript/lib/lib.webworker.importscripts.d.ts","../node_modules/typescript/lib/lib.scripthost.d.ts","../node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/typescript/lib/lib.esnext.intl.d.ts","../node_modules/axios/index.d.ts","../src/googleapi.ts","../src/index.ts","../node_modules/@types/node/assert.d.ts","../node_modules/@types/node/assert/strict.d.ts","../node_modules/@types/node/globals.d.ts","../node_modules/@types/node/async_hooks.d.ts","../node_modules/@types/node/buffer.d.ts","../node_modules/@types/node/child_process.d.ts","../node_modules/@types/node/cluster.d.ts","../node_modules/@types/node/console.d.ts","../node_modules/@types/node/constants.d.ts","../node_modules/@types/node/crypto.d.ts","../node_modules/@types/node/dgram.d.ts","../node_modules/@types/node/diagnostics_channel.d.ts","../node_modules/@types/node/dns.d.ts","../node_modules/@types/node/dns/promises.d.ts","../node_modules/@types/node/domain.d.ts","../node_modules/@types/node/events.d.ts","../node_modules/@types/node/fs.d.ts","../node_modules/@types/node/fs/promises.d.ts","../node_modules/@types/node/http.d.ts","../node_modules/@types/node/http2.d.ts","../node_modules/@types/node/https.d.ts","../node_modules/@types/node/inspector.d.ts","../node_modules/@types/node/module.d.ts","../node_modules/@types/node/net.d.ts","../node_modules/@types/node/os.d.ts","../node_modules/@types/node/path.d.ts","../node_modules/@types/node/perf_hooks.d.ts","../node_modules/@types/node/process.d.ts","../node_modules/@types/node/punycode.d.ts","../node_modules/@types/node/querystring.d.ts","../node_modules/@types/node/readline.d.ts","../node_modules/@types/node/repl.d.ts","../node_modules/@types/node/stream.d.ts","../node_modules/@types/node/stream/promises.d.ts","../node_modules/@types/node/stream/consumers.d.ts","../node_modules/@types/node/stream/web.d.ts","../node_modules/@types/node/string_decoder.d.ts","../node_modules/@types/node/timers.d.ts","../node_modules/@types/node/timers/promises.d.ts","../node_modules/@types/node/tls.d.ts","../node_modules/@types/node/trace_events.d.ts","../node_modules/@types/node/tty.d.ts","../node_modules/@types/node/url.d.ts","../node_modules/@types/node/util.d.ts","../node_modules/@types/node/v8.d.ts","../node_modules/@types/node/vm.d.ts","../node_modules/@types/node/wasi.d.ts","../node_modules/@types/node/worker_threads.d.ts","../node_modules/@types/node/zlib.d.ts","../node_modules/@types/node/globals.global.d.ts","../node_modules/@types/node/index.d.ts"],"fileInfos":["2dc8c927c9c162a773c6bb3cdc4f3286c23f10eedc67414028f9cb5951610f60",{"version":"3ac1b83264055b28c0165688fda6dfcc39001e9e7828f649299101c23ad0a0c3","affectsGlobalScope":true},"dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6","7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467","8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9","5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06","e6b724280c694a9f588847f754198fb96c43d805f065c3a5b28bbc9594541c84","e21c071ca3e1b4a815d5f04a7475adcaeea5d64367e840dd0154096d705c3940",{"version":"72704b10d97777e15f1a581b73f88273037ef752d2e50b72287bd0a90af64fe6","affectsGlobalScope":true},{"version":"7fac8cb5fc820bc2a59ae11ef1c5b38d3832c6d0dfaec5acdb5569137d09a481","affectsGlobalScope":true},{"version":"097a57355ded99c68e6df1b738990448e0bf170e606707df5a7c0481ff2427cd","affectsGlobalScope":true},{"version":"d8996609230d17e90484a2dd58f22668f9a05a3bfe00bfb1d6271171e54a31fb","affectsGlobalScope":true},{"version":"43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c","affectsGlobalScope":true},{"version":"cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a","affectsGlobalScope":true},{"version":"c5c05907c02476e4bde6b7e76a79ffcd948aedd14b6a8f56e4674221b0417398","affectsGlobalScope":true},{"version":"0d5f52b3174bee6edb81260ebcd792692c32c81fd55499d69531496f3f2b25e7","affectsGlobalScope":true},{"version":"810627a82ac06fb5166da5ada4159c4ec11978dfbb0805fe804c86406dab8357","affectsGlobalScope":true},{"version":"62d80405c46c3f4c527ee657ae9d43fda65a0bf582292429aea1e69144a522a6","affectsGlobalScope":true},{"version":"3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93","affectsGlobalScope":true},{"version":"75ec0bdd727d887f1b79ed6619412ea72ba3c81d92d0787ccb64bab18d261f14","affectsGlobalScope":true},{"version":"3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006","affectsGlobalScope":true},{"version":"17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a","affectsGlobalScope":true},{"version":"7ce9f0bde3307ca1f944119f6365f2d776d281a393b576a18a2f2893a2d75c98","affectsGlobalScope":true},{"version":"6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577","affectsGlobalScope":true},{"version":"12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d","affectsGlobalScope":true},{"version":"b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e","affectsGlobalScope":true},{"version":"0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a","affectsGlobalScope":true},{"version":"da233fc1c8a377ba9e0bed690a73c290d843c2c3d23a7bd7ec5cd3d7d73ba1e0","affectsGlobalScope":true},{"version":"d154ea5bb7f7f9001ed9153e876b2d5b8f5c2bb9ec02b3ae0d239ec769f1f2ae","affectsGlobalScope":true},{"version":"bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c","affectsGlobalScope":true},{"version":"c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8","affectsGlobalScope":true},{"version":"9d57b2b5d15838ed094aa9ff1299eecef40b190722eb619bac4616657a05f951","affectsGlobalScope":true},{"version":"6c51b5dd26a2c31dbf37f00cfc32b2aa6a92e19c995aefb5b97a3a64f1ac99de","affectsGlobalScope":true},{"version":"6e7997ef61de3132e4d4b2250e75343f487903ddf5370e7ce33cf1b9db9a63ed","affectsGlobalScope":true},{"version":"2ad234885a4240522efccd77de6c7d99eecf9b4de0914adb9a35c0c22433f993","affectsGlobalScope":true},{"version":"1b3fe904465430e030c93239a348f05e1be80640d91f2f004c3512c2c2c89f34","affectsGlobalScope":true},{"version":"3787b83e297de7c315d55d4a7c546ae28e5f6c0a361b7a1dcec1f1f50a54ef11","affectsGlobalScope":true},{"version":"e7e8e1d368290e9295ef18ca23f405cf40d5456fa9f20db6373a61ca45f75f40","affectsGlobalScope":true},{"version":"faf0221ae0465363c842ce6aa8a0cbda5d9296940a8e26c86e04cc4081eea21e","affectsGlobalScope":true},{"version":"06393d13ea207a1bfe08ec8d7be562549c5e2da8983f2ee074e00002629d1871","affectsGlobalScope":true},{"version":"5075b36ab861c8c0c45377cb8c96270d7c65f0eeaf105d53fac6850da61f1027","affectsGlobalScope":true},{"version":"10bbdc1981b8d9310ee75bfac28ee0477bb2353e8529da8cff7cb26c409cb5e8","affectsGlobalScope":true},"2808645b990069e5f8b5ff14c9f1e6077eb642583c3f7854012d60757f23c70e","7a565d5da742a6b6641b12c1b37ddb73728669ad6aab836ae8029e88cb2df6a7","06af06a8a452c173b9e09412db07f7d97204161d78295775745fb88270fc817e","0cba3a5d7b81356222594442753cf90dd2892e5ccfe1d262aaca6896ba6c1380","a69c09dbea52352f479d3e7ac949fde3d17b195abe90b045d619f747b38d6d1a",{"version":"c2ab70bbc7a24c42a790890739dd8a0ba9d2e15038b40dff8163a97a5d148c00","affectsGlobalScope":true},"422dbb183fdced59425ca072c8bd09efaa77ce4e2ab928ec0d8a1ce062d2a45a",{"version":"712ba0d43b44d144dfd01593f61af6e2e21cfae83e834d297643e7973e55ed61","affectsGlobalScope":true},"1dab5ab6bcf11de47ab9db295df8c4f1d92ffa750e8f095e88c71ce4c3299628","f71f46ccd5a90566f0a37b25b23bc4684381ab2180bdf6733f4e6624474e1894",{"version":"54e65985a3ee3cec182e6a555e20974ea936fc8b8d1738c14e8ed8a42bd921d4","affectsGlobalScope":true},"82408ed3e959ddc60d3e9904481b5a8dc16469928257af22a3f7d1a3bc7fd8c4","98a3ebfa494b46265634a73459050befba5da8fdc6ca0ef9b7269421780f4ff3","34e5de87d983bc6aefef8b17658556e3157003e8d9555d3cb098c6bef0b5fbc8","cc0b61316c4f37393f1f9595e93b673f4184e9d07f4c127165a490ec4a928668","f27371653aded82b2b160f7a7033fb4a5b1534b6f6081ef7be1468f0f15327d3","c762cd6754b13a461c54b59d0ae0ab7aeef3c292c6cf889873f786ee4d8e75c9","f4ea7d5df644785bd9fbf419930cbaec118f0d8b4160037d2339b8e23c059e79",{"version":"bfea28e6162ed21a0aeed181b623dcf250aa79abf49e24a6b7e012655af36d81","affectsGlobalScope":true},"7a5459efa09ea82088234e6533a203d528c594b01787fb90fba148885a36e8b6","ae97e20f2e10dbeec193d6a2f9cd9a367a1e293e7d6b33b68bacea166afd7792","10d4796a130577d57003a77b95d8723530bbec84718e364aa2129fa8ffba0378","ad41bb744149e92adb06eb953da195115620a3f2ad48e7d3ae04d10762dae197","bf73c576885408d4a176f44a9035d798827cc5020d58284cb18d7573430d9022","7ae078ca42a670445ae0c6a97c029cb83d143d62abd1730efb33f68f0b2c0e82",{"version":"e8b18c6385ff784228a6f369694fcf1a6b475355ba89090a88de13587a9391d5","affectsGlobalScope":true},"5d0a9ea09d990b5788f867f1c79d4878f86f7384cb7dab38eecbf22f9efd063d","12eea70b5e11e924bb0543aea5eadc16ced318aa26001b453b0d561c2fd0bd1e","08777cd9318d294646b121838574e1dd7acbb22c21a03df84e1f2c87b1ad47f2","08a90bcdc717df3d50a2ce178d966a8c353fd23e5c392fd3594a6e39d9bb6304",{"version":"4cd4cff679c9b3d9239fd7bf70293ca4594583767526916af8e5d5a47d0219c7","affectsGlobalScope":true},"2a12d2da5ac4c4979401a3f6eaafa874747a37c365e4bc18aa2b171ae134d21b","002b837927b53f3714308ecd96f72ee8a053b8aeb28213d8ec6de23ed1608b66","1dc9c847473bb47279e398b22c740c83ea37a5c88bf66629666e3cf4c5b9f99c","a9e4a5a24bf2c44de4c98274975a1a705a0abbaad04df3557c2d3cd8b1727949","00fa7ce8bc8acc560dc341bbfdf37840a8c59e6a67c9bfa3fa5f36254df35db2","1b952304137851e45bc009785de89ada562d9376177c97e37702e39e60c2f1ff",{"version":"806ef4cac3b3d9fa4a48d849c8e084d7c72fcd7b16d76e06049a9ed742ff79c0","affectsGlobalScope":true},"44b8b584a338b190a59f4f6929d072431950c7bd92ec2694821c11bce180c8a5","5f0ed51db151c2cdc4fa3bb0f44ce6066912ad001b607a34e65a96c52eb76248",{"version":"3345c276cab0e76dda86c0fb79104ff915a4580ba0f3e440870e183b1baec476","affectsGlobalScope":true},"664d8f2d59164f2e08c543981453893bc7e003e4dfd29651ce09db13e9457980","e383ff72aabf294913f8c346f5da1445ae6ad525836d28efd52cbadc01a361a6","f52fbf64c7e480271a9096763c4882d356b05cab05bf56a64e68a95313cd2ce2","59bdb65f28d7ce52ccfc906e9aaf422f8b8534b2d21c32a27d7819be5ad81df7",{"version":"3a2da34079a2567161c1359316a32e712404b56566c45332ac9dcee015ecce9f","affectsGlobalScope":true},"28a2e7383fd898c386ffdcacedf0ec0845e5d1a86b5a43f25b86bc315f556b79","3aff9c8c36192e46a84afe7b926136d520487155154ab9ba982a8b544ea8fc95","a880cf8d85af2e4189c709b0fea613741649c0e40fffb4360ec70762563d5de0","85bbf436a15bbeda4db888be3062d47f99c66fd05d7c50f0f6473a9151b6a070","9f9c49c95ecd25e0cb2587751925976cf64fd184714cb11e213749c80cf0f927","f0c75c08a71f9212c93a719a25fb0320d53f2e50ca89a812640e08f8ad8c408c",{"version":"ab9b9a36e5284fd8d3bf2f7d5fcbc60052f25f27e4d20954782099282c60d23e","affectsGlobalScope":true},"9cafe917bf667f1027b2bb62e2de454ecd2119c80873ad76fc41d941089753b8"],"options":{"declaration":true,"esModuleInterop":true,"module":1,"outDir":"./","skipLibCheck":true,"target":1},"fileIdsList":[[46,89],[49,89],[50,55,89],[51,61,62,69,78,88,89],[51,52,61,69,89],[53,89],[54,55,62,70,89],[55,78,85,89],[56,58,61,69,89],[57,89],[58,59,89],[60,61,89],[61,89],[61,62,63,78,88,89],[61,62,63,78,89],[89],[64,69,78,88,89],[61,62,64,65,69,78,85,88,89],[64,66,78,85,88,89],[46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95],[61,67,89],[68,88,89],[58,61,69,78,89],[70,89],[71,89],[49,72,89],[73,87,89,93],[74,89],[75,89],[61,76,89],[76,77,89,91],[61,78,79,80,89],[78,80,89],[78,79,89],[81,89],[82,89],[61,83,84,89],[83,84,89],[55,69,78,85,89],[86,89],[69,87,89],[50,64,75,88,89],[55,89],[78,89,90],[89,91],[89,92],[50,55,61,63,72,78,88,89,91,93],[78,89,94],[43,89],[44,89]],"referencedMap":[[46,1],[47,1],[49,2],[50,3],[51,4],[52,5],[53,6],[54,7],[55,8],[56,9],[57,10],[58,11],[59,11],[60,12],[61,13],[62,14],[63,15],[48,16],[95,16],[64,17],[65,18],[66,19],[96,20],[67,21],[68,22],[69,23],[70,24],[71,25],[72,26],[73,27],[74,28],[75,29],[76,30],[77,31],[78,32],[80,33],[79,34],[81,35],[82,36],[83,37],[84,38],[85,39],[86,40],[87,41],[88,42],[89,43],[90,44],[91,45],[92,46],[93,47],[94,48],[43,16],[1,16],[9,16],[13,16],[12,16],[3,16],[14,16],[15,16],[16,16],[17,16],[18,16],[19,16],[20,16],[21,16],[4,16],[5,16],[25,16],[22,16],[23,16],[24,16],[26,16],[27,16],[28,16],[6,16],[29,16],[30,16],[31,16],[32,16],[7,16],[33,16],[34,16],[35,16],[36,16],[8,16],[41,16],[37,16],[38,16],[39,16],[40,16],[2,16],[42,16],[11,16],[10,16],[44,49],[45,50]],"exportedModulesMap":[[46,1],[47,1],[49,2],[50,3],[51,4],[52,5],[53,6],[54,7],[55,8],[56,9],[57,10],[58,11],[59,11],[60,12],[61,13],[62,14],[63,15],[48,16],[95,16],[64,17],[65,18],[66,19],[96,20],[67,21],[68,22],[69,23],[70,24],[71,25],[72,26],[73,27],[74,28],[75,29],[76,30],[77,31],[78,32],[80,33],[79,34],[81,35],[82,36],[83,37],[84,38],[85,39],[86,40],[87,41],[88,42],[89,43],[90,44],[91,45],[92,46],[93,47],[94,48],[43,16],[1,16],[9,16],[13,16],[12,16],[3,16],[14,16],[15,16],[16,16],[17,16],[18,16],[19,16],[20,16],[21,16],[4,16],[5,16],[25,16],[22,16],[23,16],[24,16],[26,16],[27,16],[28,16],[6,16],[29,16],[30,16],[31,16],[32,16],[7,16],[33,16],[34,16],[35,16],[36,16],[8,16],[41,16],[37,16],[38,16],[39,16],[40,16],[2,16],[42,16],[11,16],[10,16],[44,49],[45,50]],"semanticDiagnosticsPerFile":[46,47,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,48,95,64,65,66,96,67,68,69,70,71,72,73,74,75,76,77,78,80,79,81,82,83,84,85,86,87,88,89,90,91,92,93,94,43,1,9,13,12,3,14,15,16,17,18,19,20,21,4,5,25,22,23,24,26,27,28,6,29,30,31,32,7,33,34,35,36,8,41,37,38,39,40,2,42,11,10,44,45]},"version":"4.6.2"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gzhangx/googleapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.03",
|
|
4
4
|
"description": "google api helper",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": ["lib/**/*"],
|
|
6
8
|
"scripts": {
|
|
7
9
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
10
|
},
|
package/pub.bat
DELETED
package/src/googleApi.ts
DELETED
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//rootUrl = 'https://accounts.google.com/o/oauth2/v2/auth';
|
|
3
|
-
//opts = { access_type: 'offline', scope: 'https://www.googleapis.com/auth/spreadsheets', response_type: 'code', client_id: 'client_id', redirect_uri: 'urn:ietf:wg:oauth:2.0:oob' }
|
|
4
|
-
//return rootUrl + '?' + querystring.stringify(opts);
|
|
5
|
-
//'https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fspreadsheets&response_type=code&client_id=client_id&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob'
|
|
6
|
-
|
|
7
|
-
import axios, {Method} from 'axios';
|
|
8
|
-
|
|
9
|
-
export interface IGClientCreds {
|
|
10
|
-
client_id: string;
|
|
11
|
-
client_secret: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface IRefresCreds extends IGClientCreds {
|
|
15
|
-
refresh_token: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export function getFormData(obj: { [id: string]: any }): (string|null) {
|
|
20
|
-
if (!obj) return null;
|
|
21
|
-
const keys = Object.keys(obj);
|
|
22
|
-
const data = keys.map(key => {
|
|
23
|
-
let v = obj[key];
|
|
24
|
-
if (typeof v === 'number') v = '' + v;
|
|
25
|
-
return `${key}=${encodeURIComponent(obj[key])}`;
|
|
26
|
-
}).join('&')
|
|
27
|
-
return data;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface IIdRange {
|
|
31
|
-
id: string; range: string;
|
|
32
|
-
}
|
|
33
|
-
type IAppendFunc = (idRng: IIdRange, data: any, opts?: any) => Promise<any>;
|
|
34
|
-
type IReadFunc = (idRng: IIdRange) => Promise<any>;
|
|
35
|
-
export interface IGoogleClient {
|
|
36
|
-
access_token: string;
|
|
37
|
-
expires_on: number;
|
|
38
|
-
token_type: string;
|
|
39
|
-
doBatchUpdate: (id: string, data: any) => Promise<any>;
|
|
40
|
-
append: IAppendFunc;
|
|
41
|
-
read: IReadFunc;
|
|
42
|
-
getSheeOps: (id: string) => {
|
|
43
|
-
doBatchUpdate: (data: any) => Promise<any>;
|
|
44
|
-
append: (range:string, data: any, opts?: any) => Promise<any>;
|
|
45
|
-
read: (range:string)=>Promise<any>;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export interface IGoogleToken {
|
|
50
|
-
access_token: string;
|
|
51
|
-
expires_in: number;
|
|
52
|
-
refresh_token: string;
|
|
53
|
-
scope: string;
|
|
54
|
-
token_type: string; //'Bearer'
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export async function getTokenFromCode(creds: IGClientCreds, code:string, redirect_uri:string) : Promise<IGoogleToken> {
|
|
58
|
-
const { client_id, client_secret } = creds;
|
|
59
|
-
const dataStr = getFormData({
|
|
60
|
-
client_secret,
|
|
61
|
-
client_id,
|
|
62
|
-
code,
|
|
63
|
-
redirect_uri,
|
|
64
|
-
grant_type: 'authorization_code'
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const tokenBody = await axios.post('https://oauth2.googleapis.com/token', dataStr,
|
|
68
|
-
{ headers: { "Content-Type": "application/x-www-form-urlencoded" } }).then(r => {
|
|
69
|
-
return r.data;
|
|
70
|
-
});
|
|
71
|
-
return tokenBody;
|
|
72
|
-
}
|
|
73
|
-
async function doRefresh(creds: IRefresCreds): Promise<IGoogleClient> {
|
|
74
|
-
const { refresh_token, client_id, client_secret } = creds;
|
|
75
|
-
|
|
76
|
-
const dataStr = getFormData({
|
|
77
|
-
client_secret,
|
|
78
|
-
client_id,
|
|
79
|
-
refresh_token,
|
|
80
|
-
grant_type: 'refresh_token'
|
|
81
|
-
});
|
|
82
|
-
const refreshBody = await axios.post('https://oauth2.googleapis.com/token', dataStr,
|
|
83
|
-
{ headers: { "Content-Type": "application/x-www-form-urlencoded" } }).then(r => {
|
|
84
|
-
return r.data;
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const {
|
|
88
|
-
access_token, expires_in, token_type
|
|
89
|
-
} = refreshBody;
|
|
90
|
-
const doOp = (op: string, id: string, postFix: string, data?: any) =>
|
|
91
|
-
axios({
|
|
92
|
-
url: `https://sheets.googleapis.com/v4/spreadsheets/${id}${postFix}`,
|
|
93
|
-
headers: {
|
|
94
|
-
"Content-Type": "application/json",
|
|
95
|
-
"Authorization": `Bearer ${access_token}`,
|
|
96
|
-
},
|
|
97
|
-
method:op as Method,
|
|
98
|
-
data,
|
|
99
|
-
}).then(r => {
|
|
100
|
-
return (r.data)
|
|
101
|
-
});
|
|
102
|
-
const doPost = (id:string, postFix:string, data:any) => doOp('post', id, postFix, data);
|
|
103
|
-
const doBatchUpdate = async (id:string, data:any) => doPost(id, ':batchUpdate', data);
|
|
104
|
-
const append: IAppendFunc = async ({ id, range }, data, opts) => {
|
|
105
|
-
if (!opts) {
|
|
106
|
-
opts = {}
|
|
107
|
-
}
|
|
108
|
-
if (!opts.valueInputOption) opts.valueInputOption = 'USER_ENTERED';
|
|
109
|
-
return await doPost(id, `/values/${range}:append?${getFormData(opts)}`, { values: data });
|
|
110
|
-
};
|
|
111
|
-
const read: IReadFunc = async ({ id, range }) => doOp('get', id, `/values/${range}`);
|
|
112
|
-
return {
|
|
113
|
-
access_token,
|
|
114
|
-
expires_on: new Date().getTime() + (expires_in * 1000 - 2000),
|
|
115
|
-
token_type,
|
|
116
|
-
doBatchUpdate,
|
|
117
|
-
append,
|
|
118
|
-
read,
|
|
119
|
-
getSheeOps: id => {
|
|
120
|
-
return {
|
|
121
|
-
doBatchUpdate: data => doBatchUpdate(id, data),
|
|
122
|
-
append: (range, data, ops) => append({ id, range }, data, ops),
|
|
123
|
-
read: range => read({ id, range }),
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const clients = {} as {
|
|
130
|
-
[name: string]: IGoogleClient;
|
|
131
|
-
};
|
|
132
|
-
export async function getClient(creds: IRefresCreds) {
|
|
133
|
-
const name = creds.client_id;
|
|
134
|
-
let client = clients[name];
|
|
135
|
-
const now = new Date().getTime();
|
|
136
|
-
if (!client || client.expires_on <= now) {
|
|
137
|
-
client = await doRefresh(creds);
|
|
138
|
-
if (!client) return null;
|
|
139
|
-
clients[name] = client;
|
|
140
|
-
}
|
|
141
|
-
return client;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function getClientCredsByEnv(envName: string) {
|
|
145
|
-
const creds: IGClientCreds = {
|
|
146
|
-
client_id: process.env[`google.${envName}.client_id`] as string,
|
|
147
|
-
client_secret: process.env[`google.${envName}.client_secret`] as string,
|
|
148
|
-
};
|
|
149
|
-
return creds;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export async function getClientByEnv(envName: string) {
|
|
153
|
-
const creds: IRefresCreds = {
|
|
154
|
-
client_id: process.env[`google.${envName}.client_id`] as string,
|
|
155
|
-
client_secret: process.env[`google.${envName}.client_secret`] as string,
|
|
156
|
-
refresh_token: process.env[`google.${envName}.refresh_token`] as string,
|
|
157
|
-
};
|
|
158
|
-
return getClient(creds);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export async function test(d:boolean) {
|
|
162
|
-
const cli = await getClientByEnv('gzprem');
|
|
163
|
-
|
|
164
|
-
if (!cli) return console.log('failed to get client');
|
|
165
|
-
const id = '1MO27odjCsxk6MWL0DygubU53hrtt3OB8SEnqjpUHJ-U';
|
|
166
|
-
if (d) return;
|
|
167
|
-
console.log('do batch update');
|
|
168
|
-
await cli.doBatchUpdate(id, {
|
|
169
|
-
"requests": [
|
|
170
|
-
{
|
|
171
|
-
"updateDimensionProperties": {
|
|
172
|
-
"range": {
|
|
173
|
-
"sheetId": 0,
|
|
174
|
-
"dimension": "COLUMNS",
|
|
175
|
-
"startIndex": 0,
|
|
176
|
-
"endIndex": 1
|
|
177
|
-
},
|
|
178
|
-
"properties": {
|
|
179
|
-
"pixelSize": 160
|
|
180
|
-
},
|
|
181
|
-
"fields": "pixelSize"
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
})
|
|
187
|
-
console.log('do batch update 2');
|
|
188
|
-
const upres = await cli.doBatchUpdate(id, {
|
|
189
|
-
"requests": [
|
|
190
|
-
{
|
|
191
|
-
|
|
192
|
-
"updateCells": {
|
|
193
|
-
"fields": "*",
|
|
194
|
-
"range": {
|
|
195
|
-
"sheetId": 0,
|
|
196
|
-
"startColumnIndex": 0,
|
|
197
|
-
"endColumnIndex": 10,
|
|
198
|
-
"startRowIndex": 0,
|
|
199
|
-
"endRowIndex": 10
|
|
200
|
-
},
|
|
201
|
-
"rows": [
|
|
202
|
-
{
|
|
203
|
-
"values": [
|
|
204
|
-
{
|
|
205
|
-
"userEnteredFormat": {
|
|
206
|
-
"backgroundColor": {
|
|
207
|
-
"blue": 10,
|
|
208
|
-
"green": 10,
|
|
209
|
-
"red": 255
|
|
210
|
-
},
|
|
211
|
-
"borders": {
|
|
212
|
-
"bottom": {
|
|
213
|
-
"style": "SOLID",
|
|
214
|
-
"width": 8,
|
|
215
|
-
"color": {
|
|
216
|
-
"blue": 0,
|
|
217
|
-
"green": 255,
|
|
218
|
-
"red": 0
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
"userEnteredValue": { "stringValue": "strstsdfasdf" }
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
"userEnteredValue": { "stringValue": "col1" }
|
|
227
|
-
}
|
|
228
|
-
]
|
|
229
|
-
}
|
|
230
|
-
]
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
]
|
|
234
|
-
});
|
|
235
|
-
console.log(upres);
|
|
236
|
-
|
|
237
|
-
console.log('append 1');
|
|
238
|
-
const appres = await cli.append({
|
|
239
|
-
id,
|
|
240
|
-
range: `'Sheet1'!A1:B2`
|
|
241
|
-
}, [
|
|
242
|
-
['aaa', 'bbb1']
|
|
243
|
-
])
|
|
244
|
-
console.log('append res');
|
|
245
|
-
console.log(appres);
|
|
246
|
-
|
|
247
|
-
console.log('read');
|
|
248
|
-
const rres = await cli.read({
|
|
249
|
-
id,
|
|
250
|
-
range: 'A1:B4'
|
|
251
|
-
});
|
|
252
|
-
console.log('read res');
|
|
253
|
-
console.log(rres);
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const sheet = cli.getSheeOps(id);
|
|
258
|
-
sheet.doBatchUpdate({
|
|
259
|
-
"requests": [
|
|
260
|
-
{
|
|
261
|
-
"updateDimensionProperties": {
|
|
262
|
-
"range": {
|
|
263
|
-
"sheetId": 0,
|
|
264
|
-
"dimension": "COLUMNS",
|
|
265
|
-
"startIndex": 0,
|
|
266
|
-
"endIndex": 1
|
|
267
|
-
},
|
|
268
|
-
"properties": {
|
|
269
|
-
"pixelSize": 100
|
|
270
|
-
},
|
|
271
|
-
"fields": "pixelSize"
|
|
272
|
-
},
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
]
|
|
276
|
-
})
|
|
277
|
-
await sheet.append('A:B', [['c', 'D']]);
|
|
278
|
-
console.log(await sheet.read('A1:B4'));
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
//test().catch(err => {
|
|
282
|
-
// console.log(err.response.text);
|
|
283
|
-
//})
|
|
284
|
-
|
|
285
|
-
/*
|
|
286
|
-
async function test2() {
|
|
287
|
-
const creds = getClientCredsByEnv('gzperm');
|
|
288
|
-
await getTokenFromCode(creds, '4/xxxx', 'http://localhost:3000');
|
|
289
|
-
}
|
|
290
|
-
console.log('invoking test2')
|
|
291
|
-
test2().catch(err => {
|
|
292
|
-
console.log('error');
|
|
293
|
-
//console.log(err);
|
|
294
|
-
console.log(err.response.text || err.response.data);
|
|
295
|
-
})
|
|
296
|
-
*/
|
package/src/index.ts
DELETED
package/test.bat
DELETED
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"incremental": true, /* Enable incremental compilation */
|
|
4
|
-
"target": "es5", /* Specify ECMAScript target version: */
|
|
5
|
-
"module": "commonjs", /* 'none', 'commonjs', 'amd', 'system', etc */
|
|
6
|
-
"declaration": true, /* Concatenate & emit output to single file.*/
|
|
7
|
-
"outDir": "lib", /* Redirect output to the directory. */
|
|
8
|
-
"esModuleInterop": true, /* Enables intero between CommonJS and ES */
|
|
9
|
-
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
10
|
-
"forceConsistentCasingInFileNames": true /* Disallow inconsistently */
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"src"
|
|
14
|
-
]
|
|
15
|
-
}
|