@gzhangx/googleapi 0.0.6 → 0.0.9

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.
@@ -22,9 +22,6 @@ export interface IGoogleUpdateParms {
22
22
  responseValueRenderOption?: 'FORMATTED_VALUE' | 'UNFORMATTED_VALUE' | 'FORMULA';
23
23
  responseDateTimeRenderOption?: 'FORMATTED_STRING' | 'SERIAL_NUMBER';
24
24
  }
25
- export declare function getFormData(obj: {
26
- [id: string]: any;
27
- }): (string | null);
28
25
  interface IIdRange {
29
26
  id: string;
30
27
  range: string;
@@ -42,6 +39,10 @@ export interface IGoogleClient {
42
39
  doBatchUpdate: (data: any) => Promise<any>;
43
40
  append: (range: string, data: any, opts?: any) => Promise<any>;
44
41
  read: (range: string) => Promise<any>;
42
+ sheetInfo: () => Promise<ISheetInfoSimple[]>;
43
+ createSheet: (sheetId: string, title: string) => Promise<any>;
44
+ updateValues: (range: string, values: string[][], opts?: IGoogleUpdateParms) => Promise<any>;
45
+ addSheet: (title: string) => Promise<any>;
45
46
  };
46
47
  }
47
48
  export interface IGoogleToken {
package/lib/googleApi.js CHANGED
@@ -54,22 +54,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
54
54
  return (mod && mod.__esModule) ? mod : { "default": mod };
55
55
  };
56
56
  Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.test = exports.getClientByEnv = exports.getClientCredsByEnv = exports.getClient = exports.getTokenFromCode = exports.getFormData = void 0;
57
+ exports.test = exports.getClientByEnv = exports.getClientCredsByEnv = exports.getClient = exports.getTokenFromCode = void 0;
58
58
  var axios_1 = __importDefault(require("axios"));
59
+ var util_1 = require("./util");
59
60
  ;
60
- function getFormData(obj) {
61
- if (!obj)
62
- return null;
63
- var keys = Object.keys(obj);
64
- var data = keys.map(function (key) {
65
- var v = obj[key];
66
- if (typeof v === 'number')
67
- v = '' + v;
68
- return "".concat(key, "=").concat(encodeURIComponent(obj[key]));
69
- }).join('&');
70
- return data;
71
- }
72
- exports.getFormData = getFormData;
73
61
  function getTokenFromCode(creds, code, redirect_uri) {
74
62
  return __awaiter(this, void 0, void 0, function () {
75
63
  var client_id, client_secret, dataStr, tokenBody;
@@ -77,7 +65,7 @@ function getTokenFromCode(creds, code, redirect_uri) {
77
65
  switch (_a.label) {
78
66
  case 0:
79
67
  client_id = creds.client_id, client_secret = creds.client_secret;
80
- dataStr = getFormData({
68
+ dataStr = (0, util_1.getFormData)({
81
69
  client_secret: client_secret,
82
70
  client_id: client_id,
83
71
  code: code,
@@ -103,7 +91,7 @@ function doRefresh(creds) {
103
91
  switch (_a.label) {
104
92
  case 0:
105
93
  refresh_token = creds.refresh_token, client_id = creds.client_id, client_secret = creds.client_secret;
106
- dataStr = getFormData({
94
+ dataStr = (0, util_1.getFormData)({
107
95
  client_secret: client_secret,
108
96
  client_id: client_id,
109
97
  refresh_token: refresh_token,
@@ -143,7 +131,7 @@ function doRefresh(creds) {
143
131
  }
144
132
  if (!opts.valueInputOption)
145
133
  opts.valueInputOption = 'USER_ENTERED';
146
- return [4 /*yield*/, doPost(id, "/values/".concat(range, ":append?").concat(getFormData(opts)), { values: data })];
134
+ return [4 /*yield*/, doPost(id, "/values/".concat(range, ":append?").concat((0, util_1.getFormData)(opts)), { values: data })];
147
135
  case 1: return [2 /*return*/, _b.sent()];
148
136
  }
149
137
  });
@@ -208,7 +196,7 @@ function doRefresh(creds) {
208
196
  }
209
197
  if (!opts.valueInputOption)
210
198
  opts.valueInputOption = 'USER_ENTERED';
211
- return doOp('put', id, "/values/".concat(range, "?").concat(getFormData(opts)), {
199
+ return doOp('put', id, "/values/".concat(encodeURIComponent(range), "?").concat((0, util_1.getFormData)(opts)), {
212
200
  values: values,
213
201
  });
214
202
  },
@@ -287,12 +275,23 @@ function getClientByEnv(envName) {
287
275
  exports.getClientByEnv = getClientByEnv;
288
276
  function test(d) {
289
277
  return __awaiter(this, void 0, void 0, function () {
290
- var cli, id, upres, appres, rres, sheet, _a, _b;
278
+ var cli, ops, rrr, id, upres, appres, rres, sheet, _a, _b;
291
279
  return __generator(this, function (_c) {
292
280
  switch (_c.label) {
293
- case 0: return [4 /*yield*/, getClientByEnv('gzprem')];
281
+ case 0: return [4 /*yield*/, getClientByEnv('gzperm')];
294
282
  case 1:
295
283
  cli = _c.sent();
284
+ return [4 /*yield*/, cli.getSheetOps('1u_AR8y7iCRPGyDhdOb1cHhjL-vclCIxuLkMhIxd08mU')];
285
+ case 2:
286
+ ops = _c.sent();
287
+ console.log('update val');
288
+ return [4 /*yield*/, ops.updateValues('Sheet1!G18:G18', [['1']])];
289
+ case 3:
290
+ rrr = _c.sent();
291
+ console.log('update done');
292
+ console.log(rrr);
293
+ if (d)
294
+ return [2 /*return*/];
296
295
  if (!cli)
297
296
  return [2 /*return*/, console.log('failed to get client')];
298
297
  id = '1MO27odjCsxk6MWL0DygubU53hrtt3OB8SEnqjpUHJ-U';
@@ -317,7 +316,7 @@ function test(d) {
317
316
  }
318
317
  ]
319
318
  })];
320
- case 2:
319
+ case 4:
321
320
  _c.sent();
322
321
  console.log('do batch update 2');
323
322
  return [4 /*yield*/, cli.doBatchUpdate(id, {
@@ -366,7 +365,7 @@ function test(d) {
366
365
  }
367
366
  ]
368
367
  })];
369
- case 3:
368
+ case 5:
370
369
  upres = _c.sent();
371
370
  console.log(upres);
372
371
  console.log('append 1');
@@ -376,7 +375,7 @@ function test(d) {
376
375
  }, [
377
376
  ['aaa', 'bbb1']
378
377
  ])];
379
- case 4:
378
+ case 6:
380
379
  appres = _c.sent();
381
380
  console.log('append res');
382
381
  console.log(appres);
@@ -385,7 +384,7 @@ function test(d) {
385
384
  id: id,
386
385
  range: 'A1:B4'
387
386
  })];
388
- case 5:
387
+ case 7:
389
388
  rres = _c.sent();
390
389
  console.log('read res');
391
390
  console.log(rres);
@@ -409,11 +408,11 @@ function test(d) {
409
408
  ]
410
409
  });
411
410
  return [4 /*yield*/, sheet.append('A:B', [['c', 'D']])];
412
- case 6:
411
+ case 8:
413
412
  _c.sent();
414
413
  _b = (_a = console).log;
415
414
  return [4 /*yield*/, sheet.read('A1:B4')];
416
- case 7:
415
+ case 9:
417
416
  _b.apply(_a, [_c.sent()]);
418
417
  return [2 /*return*/];
419
418
  }
@@ -421,8 +420,9 @@ function test(d) {
421
420
  });
422
421
  }
423
422
  exports.test = test;
424
- //test().catch(err => {
425
- // console.log(err.response.text);
423
+ //test(true).catch(err => {
424
+ ///console.log(err)
425
+ //console.log(err.response.data);
426
426
  //})
427
427
  /*
428
428
  async function test2() {
package/lib/index.d.ts CHANGED
@@ -1,2 +1,31 @@
1
- import { getFormData, getClient, getClientByEnv, getTokenFromCode, getClientCredsByEnv } from './googleApi';
2
- export { getFormData, getClient, getClientByEnv, getTokenFromCode, getClientCredsByEnv };
1
+ import { getFormData } from './util';
2
+ import { getClient, getClientByEnv, getTokenFromCode, getClientCredsByEnv } from './googleApi';
3
+ declare const google: {
4
+ getClient: typeof getClient;
5
+ getClientByEnv: typeof getClientByEnv;
6
+ getTokenFromCode: typeof getTokenFromCode;
7
+ getClientCredsByEnv: typeof getClientCredsByEnv;
8
+ };
9
+ import * as msauth from './msGraph/msauth';
10
+ import * as msdir from './msGraph/msdir';
11
+ import * as msExcell from './msGraph/msExcell';
12
+ declare const msGraph: {
13
+ getMsExcel(tenantClientInfo: msauth.IMsGraphCreds, prm: msdir.IMsGraphDirPrms, opt: msExcell.IMsGraphExcelItemOpt): Promise<msExcell.IMsExcelOps>;
14
+ getMsDir(creds: msauth.IMsGraphCreds, prms: msdir.IMsGraphDirPrms): Promise<msdir.IMsDirOps>;
15
+ getDriveUrl: (driveId: string, path: string) => string;
16
+ getDriveAndByIdUrl: (driveId: string, itemId: string) => string;
17
+ GGraphError: typeof msauth.GGraphError;
18
+ encodeSharedUrl(sharingUrl: string): string;
19
+ getAuth(opt: msauth.IAuthOpt): {
20
+ getRefreshToken: () => Promise<msauth.IRefreshTokenResult>;
21
+ getAccessToken: () => Promise<msauth.ITokenInfo>;
22
+ };
23
+ getDefaultAuth(opt: msauth.IMsGraphCreds): {
24
+ getRefreshToken: () => Promise<msauth.IRefreshTokenResult>;
25
+ getAccessToken: () => Promise<msauth.ITokenInfo>;
26
+ };
27
+ getDefaultMsGraphConn(tenantClientInfo: msauth.IMsGraphCreds, logger?: msauth.ILogger): Promise<msauth.IMsGraphOps>;
28
+ axiosErrorProcessing(err: any): string;
29
+ getMsGraphConn(opt: msauth.IMsGraphConn): Promise<msauth.IMsGraphOps>;
30
+ };
31
+ export { getFormData, google, msGraph };
package/lib/index.js CHANGED
@@ -1,9 +1,52 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ var desc = Object.getOwnPropertyDescriptor(m, k);
16
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
+ desc = { enumerable: true, get: function() { return m[k]; } };
18
+ }
19
+ Object.defineProperty(o, k2, desc);
20
+ }) : (function(o, m, k, k2) {
21
+ if (k2 === undefined) k2 = k;
22
+ o[k2] = m[k];
23
+ }));
24
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
26
+ }) : function(o, v) {
27
+ o["default"] = v;
28
+ });
29
+ var __importStar = (this && this.__importStar) || function (mod) {
30
+ if (mod && mod.__esModule) return mod;
31
+ var result = {};
32
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
+ __setModuleDefault(result, mod);
34
+ return result;
35
+ };
2
36
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getClientCredsByEnv = exports.getTokenFromCode = exports.getClientByEnv = exports.getClient = exports.getFormData = void 0;
37
+ exports.msGraph = exports.google = exports.getFormData = void 0;
38
+ var util_1 = require("./util");
39
+ Object.defineProperty(exports, "getFormData", { enumerable: true, get: function () { return util_1.getFormData; } });
4
40
  var googleApi_1 = require("./googleApi");
5
- Object.defineProperty(exports, "getFormData", { enumerable: true, get: function () { return googleApi_1.getFormData; } });
6
- Object.defineProperty(exports, "getClient", { enumerable: true, get: function () { return googleApi_1.getClient; } });
7
- Object.defineProperty(exports, "getClientByEnv", { enumerable: true, get: function () { return googleApi_1.getClientByEnv; } });
8
- Object.defineProperty(exports, "getTokenFromCode", { enumerable: true, get: function () { return googleApi_1.getTokenFromCode; } });
9
- Object.defineProperty(exports, "getClientCredsByEnv", { enumerable: true, get: function () { return googleApi_1.getClientCredsByEnv; } });
41
+ var google = {
42
+ getClient: googleApi_1.getClient,
43
+ getClientByEnv: googleApi_1.getClientByEnv,
44
+ getTokenFromCode: googleApi_1.getTokenFromCode,
45
+ getClientCredsByEnv: googleApi_1.getClientCredsByEnv
46
+ };
47
+ exports.google = google;
48
+ var msauth = __importStar(require("./msGraph/msauth"));
49
+ var msdir = __importStar(require("./msGraph/msdir"));
50
+ var msExcell = __importStar(require("./msGraph/msExcell"));
51
+ var msGraph = __assign(__assign(__assign({}, msauth), msdir), msExcell);
52
+ exports.msGraph = msGraph;
@@ -0,0 +1,48 @@
1
+ import { IMsGraphCreds } from "./msauth";
2
+ import { IMsGraphDirPrms } from './msdir';
3
+ export interface IMsGraphExcelItemOpt {
4
+ fileName?: string;
5
+ itemId?: string;
6
+ sheetInfo?: IWorkSheetInfo;
7
+ }
8
+ interface IWorkSheetInfo {
9
+ '@odata.context': string;
10
+ value: {
11
+ '@odata.id': string;
12
+ id: string;
13
+ name: string;
14
+ position: number;
15
+ visibility: string;
16
+ }[];
17
+ }
18
+ export interface IReadSheetValues {
19
+ '@odata.context': string;
20
+ '@odata.type': string;
21
+ '@odata.id': string;
22
+ address: string;
23
+ addressLocal: string;
24
+ columnCount: number;
25
+ cellCount: number;
26
+ columnHidden: boolean;
27
+ rowHidden: boolean;
28
+ numberFormat: string[][];
29
+ columnIndex: number;
30
+ text: string[][];
31
+ formulas: string[][];
32
+ formulasLocal: string[][];
33
+ hidden: boolean;
34
+ rowCount: number;
35
+ rowIndex: number;
36
+ valueTypes: string[][];
37
+ values: string[][];
38
+ }
39
+ export interface IMsExcelOps {
40
+ getWorkSheets: () => Promise<IWorkSheetInfo>;
41
+ createSheet: (name: string) => Promise<any>;
42
+ readAll: (name: string) => Promise<IReadSheetValues>;
43
+ readRange: (name: string, from: string, to: string) => Promise<IReadSheetValues>;
44
+ getRangeFormat: (name: string, from: string, to: string) => Promise<IReadSheetValues>;
45
+ updateRange: (name: string, from: string, to: string, values: string[][]) => Promise<IReadSheetValues>;
46
+ }
47
+ export declare function getMsExcel(tenantClientInfo: IMsGraphCreds, prm: IMsGraphDirPrms, opt: IMsGraphExcelItemOpt): Promise<IMsExcelOps>;
48
+ export {};
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getMsExcel = void 0;
40
+ var msauth_1 = require("./msauth");
41
+ var msdir_1 = require("./msdir");
42
+ function getMsExcel(tenantClientInfo, prm, opt) {
43
+ return __awaiter(this, void 0, void 0, function () {
44
+ function getWorkSheets() {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0: return [4 /*yield*/, ops.doGet(sheetUrl)];
49
+ case 1: return [2 /*return*/, _a.sent()];
50
+ }
51
+ });
52
+ });
53
+ }
54
+ function createSheet(name) {
55
+ return __awaiter(this, void 0, void 0, function () {
56
+ var _a, found;
57
+ return __generator(this, function (_b) {
58
+ switch (_b.label) {
59
+ case 0:
60
+ if (!!opt.sheetInfo) return [3 /*break*/, 2];
61
+ _a = opt;
62
+ return [4 /*yield*/, getWorkSheets()];
63
+ case 1:
64
+ _a.sheetInfo = _b.sent();
65
+ _b.label = 2;
66
+ case 2:
67
+ found = (opt.sheetInfo.value.find(function (v) { return v.name === name; }));
68
+ if (found)
69
+ return [2 /*return*/, found];
70
+ return [4 /*yield*/, ops.doPost(sheetUrl, {
71
+ name: name
72
+ })];
73
+ case 3: return [2 /*return*/, _b.sent()];
74
+ }
75
+ });
76
+ });
77
+ }
78
+ function readAll(name) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ return __generator(this, function (_a) {
81
+ return [2 /*return*/, ops.doGet(("".concat(sheetUrl, "('").concat(name, "')/usedRange")))];
82
+ });
83
+ });
84
+ }
85
+ function readRange(name, from, to) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ return __generator(this, function (_a) {
88
+ return [2 /*return*/, ops.doGet(("".concat(sheetUrl, "/").concat(name, "/range(address='").concat(from, ":").concat(to, "')")))];
89
+ });
90
+ });
91
+ }
92
+ function getRangeFormat(name, from, to) {
93
+ return __awaiter(this, void 0, void 0, function () {
94
+ return __generator(this, function (_a) {
95
+ return [2 /*return*/, ops.doGet(("".concat(sheetUrl, "/").concat(name, "/range(address='").concat(from, ":").concat(to, "')/format")))];
96
+ });
97
+ });
98
+ }
99
+ function updateRange(name, from, to, values) {
100
+ return __awaiter(this, void 0, void 0, function () {
101
+ return __generator(this, function (_a) {
102
+ return [2 /*return*/, ops.doPatch(("".concat(sheetUrl, "/").concat(name, "/range(address='").concat(from, ":").concat(to, "')")), {
103
+ values: values,
104
+ })];
105
+ });
106
+ });
107
+ }
108
+ var ops, error, dirInfo, drItmUrl, r, sheetUrl;
109
+ return __generator(this, function (_a) {
110
+ switch (_a.label) {
111
+ case 0: return [4 /*yield*/, (0, msauth_1.getDefaultMsGraphConn)(tenantClientInfo, prm.logger)];
112
+ case 1:
113
+ ops = _a.sent();
114
+ if (!!opt.itemId) return [3 /*break*/, 5];
115
+ if (!!prm.driveId) return [3 /*break*/, 3];
116
+ if (!prm.sharedUrl) {
117
+ error = "Must specify drive or sharedUrl";
118
+ prm.logger(error);
119
+ throw {
120
+ error: error,
121
+ message: error,
122
+ };
123
+ }
124
+ return [4 /*yield*/, (0, msdir_1.getMsDir)(tenantClientInfo, prm)];
125
+ case 2:
126
+ dirInfo = _a.sent();
127
+ prm.driveId = dirInfo.driveId;
128
+ _a.label = 3;
129
+ case 3:
130
+ drItmUrl = "".concat((0, msdir_1.getDriveUrl)(prm.driveId, opt.fileName));
131
+ return [4 /*yield*/, ops.doGet(drItmUrl)];
132
+ case 4:
133
+ r = _a.sent();
134
+ opt.itemId = r.id;
135
+ prm.logger("query id for ".concat(opt.fileName, " = ").concat(opt.itemId));
136
+ _a.label = 5;
137
+ case 5:
138
+ sheetUrl = "".concat((0, msdir_1.getDriveAndByIdUrl)(prm.driveId, opt.itemId), ":/workbook/worksheets");
139
+ return [2 /*return*/, {
140
+ getWorkSheets: getWorkSheets,
141
+ createSheet: createSheet,
142
+ readAll: readAll,
143
+ readRange: readRange,
144
+ getRangeFormat: getRangeFormat,
145
+ updateRange: updateRange,
146
+ }];
147
+ }
148
+ });
149
+ });
150
+ }
151
+ exports.getMsExcel = getMsExcel;
@@ -0,0 +1,65 @@
1
+ import { AxiosRequestConfig } from "axios";
2
+ export interface IMsGraphCreds {
3
+ tenantId: string;
4
+ client_id: string;
5
+ refresh_token: string;
6
+ }
7
+ export interface IAuthOpt extends IMsGraphCreds {
8
+ promptUser: (msg: string | object, info: object) => void;
9
+ saveToken: (token: IRefreshTokenResult) => Promise<void>;
10
+ scope?: string;
11
+ pollTime?: number;
12
+ }
13
+ export interface IRefreshTokenResult {
14
+ token_type: 'Bearer';
15
+ scope: string;
16
+ expires_in: string;
17
+ ext_expires_in: string;
18
+ expires_on: string;
19
+ not_before: string;
20
+ resource: 'https://graph.microsoft.com';
21
+ access_token: string;
22
+ refresh_token: string;
23
+ id_token: string;
24
+ }
25
+ export interface ITokenInfo {
26
+ access_token: string;
27
+ expires_on: number;
28
+ }
29
+ export declare function GGraphError(message?: string): void;
30
+ export declare namespace GGraphError {
31
+ var prototype: Error;
32
+ }
33
+ export declare function encodeSharedUrl(sharingUrl: string): string;
34
+ export interface IDriveItemInfo {
35
+ id: string;
36
+ name: string;
37
+ parentReference: {
38
+ driveId: string;
39
+ id: string;
40
+ };
41
+ }
42
+ export declare function getAuth(opt: IAuthOpt): {
43
+ getRefreshToken: () => Promise<IRefreshTokenResult>;
44
+ getAccessToken: () => Promise<ITokenInfo>;
45
+ };
46
+ export declare function getDefaultAuth(opt: IMsGraphCreds): {
47
+ getRefreshToken: () => Promise<IRefreshTokenResult>;
48
+ getAccessToken: () => Promise<ITokenInfo>;
49
+ };
50
+ export interface IMsGraphConn {
51
+ tenantClientInfo: IMsGraphCreds;
52
+ tokenInfo?: ITokenInfo;
53
+ logger: (msg: string) => void;
54
+ }
55
+ export interface IMsGraphOps {
56
+ doGet: (urlPostFix: string, fmt?: (cfg: AxiosRequestConfig) => AxiosRequestConfig) => Promise<any>;
57
+ doPost: (urlPostFix: string, data: object) => Promise<any>;
58
+ doPut: (urlPostFix: string, data: object) => Promise<any>;
59
+ doPatch: (urlPostFix: string, data: object) => Promise<any>;
60
+ getSharedItemInfo: (sharedUrl: string) => Promise<IDriveItemInfo>;
61
+ }
62
+ export declare type ILogger = (msg: string) => void;
63
+ export declare function getDefaultMsGraphConn(tenantClientInfo: IMsGraphCreds, logger?: ILogger): Promise<IMsGraphOps>;
64
+ export declare function axiosErrorProcessing(err: any): string;
65
+ export declare function getMsGraphConn(opt: IMsGraphConn): Promise<IMsGraphOps>;