@anmiles/google-api-wrapper 3.1.0 → 5.0.0
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/CHANGELOG.md +9 -2
- package/README.md +20 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +5 -26
- package/dist/index.js.map +1 -1
- package/dist/lib/api/calendar.d.ts +2 -12
- package/dist/lib/api/calendar.js +3 -24
- package/dist/lib/api/calendar.js.map +1 -1
- package/dist/lib/api/shared.d.ts +2 -1
- package/dist/lib/api/shared.js +2 -2
- package/dist/lib/api/shared.js.map +1 -1
- package/dist/lib/api/youtube.d.ts +2 -8
- package/dist/lib/api/youtube.js +3 -14
- package/dist/lib/api/youtube.js.map +1 -1
- package/dist/lib/auth.d.ts +2 -1
- package/dist/lib/auth.js +3 -3
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/secrets.d.ts +2 -2
- package/dist/lib/secrets.js +4 -2
- package/dist/lib/secrets.js.map +1 -1
- package/dist/types/api.d.ts +3 -0
- package/dist/types/api.js +3 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/secrets.d.ts +3 -0
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/lib/__tests__/auth.test.ts +11 -5
- package/src/lib/__tests__/secrets.test.ts +41 -5
- package/src/lib/api/__tests__/calendar.test.ts +16 -134
- package/src/lib/api/__tests__/shared.test.ts +19 -3
- package/src/lib/api/__tests__/youtube.test.ts +16 -77
- package/src/lib/api/calendar.ts +3 -22
- package/src/lib/api/shared.ts +3 -2
- package/src/lib/api/youtube.ts +3 -12
- package/src/lib/auth.ts +4 -3
- package/src/lib/secrets.ts +6 -3
- package/src/types/api.ts +3 -0
- package/src/types/index.ts +1 -0
- package/src/types/secrets.ts +5 -0
- package/src/lib/api/__tests__/apiHelpers.ts +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -5,9 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [
|
|
8
|
+
## [5.0.0](../../tags/v5.0.0) - 2023-03-20
|
|
9
|
+
### Added
|
|
10
|
+
- Non-persistence mode for getAuth: ability to not save sensitive credentials into the file
|
|
11
|
+
|
|
12
|
+
## Removed
|
|
13
|
+
- Removed getter methods from api helpers to be able to re-use auth between api usages. Now better call `getAPI` and then run needed native methods on their own.
|
|
14
|
+
|
|
15
|
+
## [4.0.0](../../tags/v4.0.0) - 2023-03-12
|
|
9
16
|
### Changed
|
|
10
|
-
- Silent mode
|
|
17
|
+
- Silent mode for getting items
|
|
11
18
|
|
|
12
19
|
## [3.0.3](../../tags/v3.0.3) - 2023-03-12
|
|
13
20
|
### Changed
|
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ Provides quick interface for getting google API data
|
|
|
12
12
|
> $ node ./videos.js
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
### Authorization
|
|
15
16
|
``` js
|
|
16
17
|
/* auth.js */
|
|
17
18
|
|
|
@@ -22,12 +23,30 @@ login("username");
|
|
|
22
23
|
|
|
23
24
|
```
|
|
24
25
|
|
|
26
|
+
### Example with persisted auth
|
|
27
|
+
``` js
|
|
28
|
+
/* calendar.js */
|
|
29
|
+
|
|
30
|
+
import { getProfiles, getCalendarAPI } from '@anmiles/google-api-wrapper';
|
|
31
|
+
|
|
32
|
+
require('./auth');
|
|
33
|
+
|
|
34
|
+
getProfiles().map(async (profile) => {
|
|
35
|
+
const youtube = getYoutubeAPI(profile); // auth is persisted by login() function from `auth.js`
|
|
36
|
+
const videos = await youtube.getPlaylistItems(profile, { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 });
|
|
37
|
+
videos.forEach((video) => console.log(`Downloaded: ${video.snippet?.title}`));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Example with non-persisted auth
|
|
25
43
|
``` js
|
|
26
44
|
/* videos.js */
|
|
27
45
|
|
|
28
|
-
import { getProfiles,
|
|
46
|
+
import { getProfiles, getYoutubeAPI } from '@anmiles/google-api-wrapper';
|
|
29
47
|
|
|
30
48
|
getProfiles().map(async (profile) => {
|
|
49
|
+
const youtube = getYoutubeAPI(profile, { persist: false }); // false by default
|
|
31
50
|
const videos = await youtube.getPlaylistItems(profile, { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 });
|
|
32
51
|
videos.forEach((video) => console.log(`Downloaded: ${video.snippet?.title}`));
|
|
33
52
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { getAPI as getCalendarAPI } from './lib/api/calendar';
|
|
2
|
+
export { getAPI as getYoutubeAPI } from './lib/api/youtube';
|
|
3
3
|
export { getItems } from './lib/api/shared';
|
|
4
4
|
export { createProfile, getProfiles } from './lib/profiles';
|
|
5
5
|
export { login, getAuth } from './lib/auth';
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getAuth = exports.login = exports.getProfiles = exports.createProfile = exports.getItems = exports.
|
|
27
|
-
|
|
28
|
-
exports
|
|
3
|
+
exports.getAuth = exports.login = exports.getProfiles = exports.createProfile = exports.getItems = exports.getYoutubeAPI = exports.getCalendarAPI = void 0;
|
|
4
|
+
var calendar_1 = require("./lib/api/calendar");
|
|
5
|
+
Object.defineProperty(exports, "getCalendarAPI", { enumerable: true, get: function () { return calendar_1.getAPI; } });
|
|
6
|
+
var youtube_1 = require("./lib/api/youtube");
|
|
7
|
+
Object.defineProperty(exports, "getYoutubeAPI", { enumerable: true, get: function () { return youtube_1.getAPI; } });
|
|
29
8
|
var shared_1 = require("./lib/api/shared");
|
|
30
9
|
Object.defineProperty(exports, "getItems", { enumerable: true, get: function () { return shared_1.getItems; } });
|
|
31
10
|
var profiles_1 = require("./lib/profiles");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAA8D;AAArD,0GAAA,MAAM,OAAkB;AACjC,6CAA4D;AAAnD,wGAAA,MAAM,OAAiB;AAChC,2CAA4C;AAAnC,kGAAA,QAAQ,OAAA;AACjB,2CAA4D;AAAnD,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnC,mCAA4C;AAAnC,6FAAA,KAAK,OAAA;AAAE,+FAAA,OAAO,OAAA"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
getAPI: typeof getAPI;
|
|
5
|
-
getEvents: typeof getEvents;
|
|
6
|
-
getCalendars: typeof getCalendars;
|
|
7
|
-
setEvent: typeof setEvent;
|
|
8
|
-
};
|
|
9
|
-
export default _default;
|
|
10
|
-
declare function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>;
|
|
11
|
-
declare function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List): Promise<GoogleApis.calendar_v3.Schema$CalendarListEntry[]>;
|
|
12
|
-
declare function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<GoogleApis.calendar_v3.Schema$Event[]>;
|
|
13
|
-
declare function setEvent(profile: string, eventId: string | undefined, args: GoogleApis.calendar_v3.Params$Resource$Events$Update): Promise<void>;
|
|
2
|
+
import type { AuthOptions } from '../../types';
|
|
3
|
+
export declare function getAPI(profile: string, options?: AuthOptions): Promise<GoogleApis.calendar_v3.Calendar>;
|
package/dist/lib/api/calendar.js
CHANGED
|
@@ -1,35 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.getAPI = void 0;
|
|
7
4
|
const googleapis_1 = require("googleapis");
|
|
8
5
|
const auth_1 = require("../auth");
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
exports.default = { getAPI, getEvents, getCalendars, setEvent };
|
|
12
|
-
async function getAPI(profile) {
|
|
13
|
-
const googleAuth = await (0, auth_1.getAuth)(profile);
|
|
6
|
+
async function getAPI(profile, options) {
|
|
7
|
+
const googleAuth = await (0, auth_1.getAuth)(profile, options);
|
|
14
8
|
return googleapis_1.google.calendar({
|
|
15
9
|
version: 'v3',
|
|
16
10
|
auth: googleAuth,
|
|
17
11
|
});
|
|
18
12
|
}
|
|
19
13
|
exports.getAPI = getAPI;
|
|
20
|
-
async function getCalendars(profile, args) {
|
|
21
|
-
const api = await calendar_1.default.getAPI(profile);
|
|
22
|
-
return (0, shared_1.getItems)(api.calendarList, args);
|
|
23
|
-
}
|
|
24
|
-
exports.getCalendars = getCalendars;
|
|
25
|
-
async function getEvents(profile, args) {
|
|
26
|
-
const api = await calendar_1.default.getAPI(profile);
|
|
27
|
-
return (0, shared_1.getItems)(api.events, args);
|
|
28
|
-
}
|
|
29
|
-
exports.getEvents = getEvents;
|
|
30
|
-
async function setEvent(profile, eventId, args) {
|
|
31
|
-
const api = await calendar_1.default.getAPI(profile);
|
|
32
|
-
api.events.update({ eventId, ...args });
|
|
33
|
-
}
|
|
34
|
-
exports.setEvent = setEvent;
|
|
35
14
|
//# sourceMappingURL=calendar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../../src/lib/api/calendar.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../../src/lib/api/calendar.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;AAGpC,kCAAkC;AAE3B,KAAK,UAAU,MAAM,CAAC,OAAe,EAAE,OAAqB;IAClE,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAEnD,OAAO,mBAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAPD,wBAOC"}
|
package/dist/lib/api/shared.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { GetItemsOptions } from '../../types';
|
|
2
3
|
export { getItems };
|
|
3
4
|
declare const _default: {
|
|
4
5
|
getItems: typeof getItems;
|
|
@@ -16,4 +17,4 @@ type CommonResponse<TItem> = {
|
|
|
16
17
|
};
|
|
17
18
|
nextPageToken?: string | null | undefined;
|
|
18
19
|
};
|
|
19
|
-
declare function getItems<TApi extends CommonApi<TArgs, TResponse>, TItem, TArgs, TResponse extends CommonResponse<TItem>>(api: TApi, args: TArgs,
|
|
20
|
+
declare function getItems<TApi extends CommonApi<TArgs, TResponse>, TItem, TArgs, TResponse extends CommonResponse<TItem>>(api: TApi, args: TArgs, options?: GetItemsOptions): Promise<TItem[]>;
|
package/dist/lib/api/shared.js
CHANGED
|
@@ -5,14 +5,14 @@ const logger_1 = require("../logger");
|
|
|
5
5
|
const sleep_1 = require("../sleep");
|
|
6
6
|
exports.default = { getItems };
|
|
7
7
|
const requestInterval = 300;
|
|
8
|
-
async function getItems(api, args,
|
|
8
|
+
async function getItems(api, args, options) {
|
|
9
9
|
var _a, _b;
|
|
10
10
|
const items = [];
|
|
11
11
|
let pageToken = undefined;
|
|
12
12
|
do {
|
|
13
13
|
const response = await api.list({ ...args, pageToken });
|
|
14
14
|
(_a = response.data.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => items.push(item));
|
|
15
|
-
if (showProgress) {
|
|
15
|
+
if (options === null || options === void 0 ? void 0 : options.showProgress) {
|
|
16
16
|
(0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
|
|
17
17
|
}
|
|
18
18
|
pageToken = response.data.nextPageToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;AAEA,sCAAgC;AAChC,oCAAiC;AAGjC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAiB5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,KAAK,UAAU,QAAQ,CAKrB,GAAS,EAAE,IAAW,EAAE,OAAyB;;IAClD,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAAgD,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrG,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,EAAE;YAC1B,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;SAC/F;QAED,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;QACxC,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;KAC7B,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AA3CQ,4BAAQ"}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
-
|
|
3
|
-
declare
|
|
4
|
-
getAPI: typeof getAPI;
|
|
5
|
-
getPlaylistItems: typeof getPlaylistItems;
|
|
6
|
-
};
|
|
7
|
-
export default _default;
|
|
8
|
-
declare function getAPI(profile: string): Promise<GoogleApis.youtube_v3.Youtube>;
|
|
9
|
-
declare function getPlaylistItems(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]>;
|
|
2
|
+
import type { AuthOptions } from '../../types';
|
|
3
|
+
export declare function getAPI(profile: string, options?: AuthOptions): Promise<GoogleApis.youtube_v3.Youtube>;
|
package/dist/lib/api/youtube.js
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.getAPI = void 0;
|
|
7
4
|
const googleapis_1 = require("googleapis");
|
|
8
5
|
const auth_1 = require("../auth");
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
exports.default = { getAPI, getPlaylistItems };
|
|
12
|
-
async function getAPI(profile) {
|
|
13
|
-
const googleAuth = await (0, auth_1.getAuth)(profile);
|
|
6
|
+
async function getAPI(profile, options) {
|
|
7
|
+
const googleAuth = await (0, auth_1.getAuth)(profile, options);
|
|
14
8
|
return googleapis_1.google.youtube({
|
|
15
9
|
version: 'v3',
|
|
16
10
|
auth: googleAuth,
|
|
17
11
|
});
|
|
18
12
|
}
|
|
19
13
|
exports.getAPI = getAPI;
|
|
20
|
-
async function getPlaylistItems(profile, args) {
|
|
21
|
-
const api = await youtube_1.default.getAPI(profile);
|
|
22
|
-
return (0, shared_1.getItems)(api.playlistItems, args);
|
|
23
|
-
}
|
|
24
|
-
exports.getPlaylistItems = getPlaylistItems;
|
|
25
14
|
//# sourceMappingURL=youtube.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"youtube.js","sourceRoot":"","sources":["../../../src/lib/api/youtube.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"youtube.js","sourceRoot":"","sources":["../../../src/lib/api/youtube.ts"],"names":[],"mappings":";;;AAAA,2CAAoC;AAGpC,kCAAkC;AAE3B,KAAK,UAAU,MAAM,CAAC,OAAe,EAAE,OAAqB;IAClE,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAEnD,OAAO,mBAAM,CAAC,OAAO,CAAC;QACrB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAPD,wBAOC"}
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { AuthOptions } from '../types';
|
|
2
3
|
export { login, getAuth };
|
|
3
4
|
declare const _default: {
|
|
4
5
|
login: typeof login;
|
|
@@ -6,4 +7,4 @@ declare const _default: {
|
|
|
6
7
|
};
|
|
7
8
|
export default _default;
|
|
8
9
|
declare function login(profile?: string): Promise<void>;
|
|
9
|
-
declare function getAuth(profile: string): Promise<GoogleApis.Common.OAuth2Client>;
|
|
10
|
+
declare function getAuth(profile: string, options?: AuthOptions): Promise<GoogleApis.Common.OAuth2Client>;
|
package/dist/lib/auth.js
CHANGED
|
@@ -14,15 +14,15 @@ async function login(profile) {
|
|
|
14
14
|
const profiles = (0, profiles_1.getProfiles)().filter((p) => !profile || p === profile);
|
|
15
15
|
for (const profile of profiles) {
|
|
16
16
|
(0, logger_1.warn)(`${profile} - logging in...`);
|
|
17
|
-
await auth_1.default.getAuth(profile);
|
|
17
|
+
await auth_1.default.getAuth(profile, { persist: true });
|
|
18
18
|
(0, logger_1.info)(`${profile} - logged in successfully`);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
exports.login = login;
|
|
22
|
-
async function getAuth(profile) {
|
|
22
|
+
async function getAuth(profile, options) {
|
|
23
23
|
const secrets = (0, secrets_1.getSecrets)(profile);
|
|
24
24
|
const googleAuth = new googleapis_1.google.auth.OAuth2(secrets.web.client_id, secrets.web.client_secret, secrets.web.redirect_uris[0]);
|
|
25
|
-
const tokens = await (0, secrets_1.getCredentials)(profile, googleAuth);
|
|
25
|
+
const tokens = await (0, secrets_1.getCredentials)(profile, googleAuth, options);
|
|
26
26
|
googleAuth.setCredentials(tokens);
|
|
27
27
|
return googleAuth;
|
|
28
28
|
}
|
package/dist/lib/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAGpC,qCAAsC;AACtC,yCAAyC;AACzC,uCAAuD;AAEvD,kDAA0B;AAG1B,kBAAe,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAElC,KAAK,UAAU,KAAK,CAAC,OAAgB;IACpC,MAAM,QAAQ,GAAG,IAAA,sBAAW,GAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,KAAK,OAAO,CAAC,CAAC;IAExE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC/B,IAAA,aAAI,EAAC,GAAG,OAAO,kBAAkB,CAAC,CAAC;QACnC,MAAM,cAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,OAAO,EAAG,IAAI,EAAE,CAAC,CAAC;QAChD,IAAA,aAAI,EAAC,GAAG,OAAO,2BAA2B,CAAC,CAAC;KAC5C;AACF,CAAC;AAXQ,sBAAK;AAad,KAAK,UAAU,OAAO,CAAC,OAAe,EAAE,OAAqB;IAC5D,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,OAAO,CAAC,CAAC;IAEpC,MAAM,UAAU,GAAG,IAAI,mBAAM,CAAC,IAAI,CAAC,MAAM,CACxC,OAAO,CAAC,GAAG,CAAC,SAAS,EACrB,OAAO,CAAC,GAAG,CAAC,aAAa,EACzB,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAC5B,CAAC;IAEF,MAAM,MAAM,GAAG,MAAM,IAAA,wBAAc,EAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAClE,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,UAAU,CAAC;AACnB,CAAC;AAzBe,0BAAO"}
|
package/dist/lib/secrets.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { Secrets } from '../types';
|
|
2
|
+
import type { Secrets, AuthOptions } from '../types';
|
|
3
3
|
export { getSecrets, getCredentials };
|
|
4
4
|
declare const _default: {
|
|
5
5
|
getScopes: typeof getScopes;
|
|
@@ -13,7 +13,7 @@ declare const _default: {
|
|
|
13
13
|
export default _default;
|
|
14
14
|
declare function getScopes(): string[];
|
|
15
15
|
declare function getSecrets(profile: string): Secrets;
|
|
16
|
-
declare function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client): Promise<GoogleApis.Auth.Credentials>;
|
|
16
|
+
declare function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials>;
|
|
17
17
|
declare function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client): Promise<GoogleApis.Auth.Credentials>;
|
|
18
18
|
declare function checkSecrets(profile: string, secretsObject: Secrets, secretsFile: string): true | void;
|
|
19
19
|
declare function getScopesError(scopesFile: string): string;
|
package/dist/lib/secrets.js
CHANGED
|
@@ -48,9 +48,11 @@ function getSecrets(profile) {
|
|
|
48
48
|
return secretsObject;
|
|
49
49
|
}
|
|
50
50
|
exports.getSecrets = getSecrets;
|
|
51
|
-
async function getCredentials(profile, auth) {
|
|
51
|
+
async function getCredentials(profile, auth, options) {
|
|
52
52
|
const credentialsFile = (0, paths_1.getCredentialsFile)(profile);
|
|
53
|
-
return (0
|
|
53
|
+
return (options === null || options === void 0 ? void 0 : options.persist)
|
|
54
|
+
? (0, jsonLib_1.getJSONAsync)(credentialsFile, () => secrets_1.default.createCredentials(profile, auth))
|
|
55
|
+
: secrets_1.default.createCredentials(profile, auth);
|
|
54
56
|
}
|
|
55
57
|
exports.getCredentials = getCredentials;
|
|
56
58
|
async function createCredentials(profile, auth) {
|
package/dist/lib/secrets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/lib/secrets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,qDAAuC;AAGvC,uCAAkD;AAClD,qCAAuC;AACvC,mCAA4E;AAE5E,wDAAgC;AAGhC,kBAAe,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAE3H,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,WAAW,GAAI,oBAAoB,YAAY,gBAAgB,CAAC;AAEtE,SAAS,SAAS;IACjB,MAAM,UAAU,GAAG,IAAA,qBAAa,GAAE,CAAC;IACnC,MAAM,MAAM,GAAO,IAAA,iBAAO,EAAW,UAAU,EAAE,GAAG,EAAE,CAAC,IAAA,cAAK,EAAC,iBAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAU,CAAC,CAAC;IAC3G,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,OAAe;IAClC,MAAM,WAAW,GAAK,IAAA,sBAAc,EAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,IAAA,iBAAO,EAAU,WAAW,EAAE,GAAG,EAAE,CAAC,IAAA,cAAK,EAAC,iBAAO,CAAC,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAU,CAAC,CAAC;IACzH,iBAAO,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC;IAC1D,OAAO,aAAa,CAAC;AACtB,CAAC;AAjBQ,gCAAU;AAmBnB,KAAK,UAAU,cAAc,CAAC,OAAe,EAAE,IAAoC;
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/lib/secrets.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/types/api.ts"],"names":[],"mappings":""}
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
|
@@ -14,5 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api"), exports);
|
|
17
18
|
__exportStar(require("./secrets"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,4CAA0B"}
|
package/dist/types/secrets.d.ts
CHANGED
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { getAPI as getCalendarAPI } from './lib/api/calendar';
|
|
2
|
+
export { getAPI as getYoutubeAPI } from './lib/api/youtube';
|
|
3
3
|
export { getItems } from './lib/api/shared';
|
|
4
4
|
export { createProfile, getProfiles } from './lib/profiles';
|
|
5
5
|
export { login, getAuth } from './lib/auth';
|
|
@@ -58,11 +58,11 @@ describe('src/lib/auth', () => {
|
|
|
58
58
|
expect(profiles.getProfiles).toBeCalledWith();
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
it('should auth all profiles', async () => {
|
|
61
|
+
it('should auth all profiles with persistence', async () => {
|
|
62
62
|
await original.login();
|
|
63
63
|
|
|
64
64
|
allProfiles.forEach((profile) => {
|
|
65
|
-
expect(auth.getAuth).toBeCalledWith(profile);
|
|
65
|
+
expect(auth.getAuth).toBeCalledWith(profile, { persist : true });
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
68
|
|
|
@@ -78,8 +78,8 @@ describe('src/lib/auth', () => {
|
|
|
78
78
|
it('should auth only specified profile', async () => {
|
|
79
79
|
await original.login('username1');
|
|
80
80
|
|
|
81
|
-
expect(auth.getAuth).toBeCalledWith('username1');
|
|
82
|
-
expect(auth.getAuth).not.toBeCalledWith('username2');
|
|
81
|
+
expect(auth.getAuth).toBeCalledWith('username1', { persist : true });
|
|
82
|
+
expect(auth.getAuth).not.toBeCalledWith('username2', { persist : true });
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
|
|
@@ -91,7 +91,7 @@ describe('src/lib/auth', () => {
|
|
|
91
91
|
|
|
92
92
|
it('should get credentials', async () => {
|
|
93
93
|
await original.getAuth(profile);
|
|
94
|
-
expect(secrets.getCredentials).toBeCalledWith(profile, googleAuth);
|
|
94
|
+
expect(secrets.getCredentials).toBeCalledWith(profile, googleAuth, undefined);
|
|
95
95
|
});
|
|
96
96
|
|
|
97
97
|
it('should create OAuth2 instance', async () => {
|
|
@@ -104,6 +104,12 @@ describe('src/lib/auth', () => {
|
|
|
104
104
|
expect(googleAuth.setCredentials).toBeCalledWith(credentials);
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
it('should pass persistence', async () => {
|
|
108
|
+
await original.getAuth(profile, { persist : true });
|
|
109
|
+
|
|
110
|
+
expect(secrets.getCredentials).toBeCalledWith(profile, googleAuth, { persist : true });
|
|
111
|
+
});
|
|
112
|
+
|
|
107
113
|
it('should return google auth', async () => {
|
|
108
114
|
const result = await original.getAuth(profile);
|
|
109
115
|
expect(result).toEqual(googleAuth);
|
|
@@ -176,27 +176,63 @@ describe('src/lib/secrets', () => {
|
|
|
176
176
|
json = credentialsJSON;
|
|
177
177
|
});
|
|
178
178
|
|
|
179
|
-
it('should get json from credentials file', async () => {
|
|
180
|
-
await original.getCredentials(profile, auth);
|
|
179
|
+
it('should not get json from credentials file if persisting enabled', async () => {
|
|
180
|
+
await original.getCredentials(profile, auth, { persist : true });
|
|
181
181
|
|
|
182
182
|
expect(getJSONAsyncSpy).toBeCalled();
|
|
183
183
|
expect(getJSONAsyncSpy.mock.calls[0][0]).toEqual(credentialsFile);
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
-
it('should
|
|
186
|
+
it('should not get json from credentials file if persisting disabled', async () => {
|
|
187
|
+
await original.getCredentials(profile, auth, { persist : false });
|
|
188
|
+
|
|
189
|
+
expect(getJSONAsyncSpy).not.toBeCalled();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('should not get json from credentials file if persisting not specified', async () => {
|
|
187
193
|
await original.getCredentials(profile, auth);
|
|
188
194
|
|
|
195
|
+
expect(getJSONAsyncSpy).not.toBeCalled();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('should fallback to createCredentials if persisting enabled', async () => {
|
|
199
|
+
await original.getCredentials(profile, auth, { persist : true });
|
|
200
|
+
|
|
189
201
|
const fallback = getJSONAsyncSpy.mock.calls[0][1];
|
|
190
202
|
await fallback();
|
|
191
203
|
|
|
192
204
|
expect(secrets.createCredentials).toBeCalledWith(profile, auth);
|
|
193
205
|
});
|
|
194
206
|
|
|
195
|
-
it('should
|
|
196
|
-
|
|
207
|
+
it('should call createCredentials directly if persisting disabled', async () => {
|
|
208
|
+
await original.getCredentials(profile, auth, { persist : false });
|
|
209
|
+
|
|
210
|
+
expect(secrets.createCredentials).toBeCalledWith(profile, auth);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('should call createCredentials directly if persisting not specified', async () => {
|
|
214
|
+
await original.getCredentials(profile, auth);
|
|
215
|
+
|
|
216
|
+
expect(secrets.createCredentials).toBeCalledWith(profile, auth);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should return credentials if persisting enabled', async () => {
|
|
220
|
+
const result = await original.getCredentials(profile, auth, { persist : true });
|
|
197
221
|
|
|
198
222
|
expect(result).toEqual(credentialsJSON);
|
|
199
223
|
});
|
|
224
|
+
|
|
225
|
+
it('should return nothing if persisting disabled', async () => {
|
|
226
|
+
const result = await original.getCredentials(profile, auth, { persist : false });
|
|
227
|
+
|
|
228
|
+
expect(result).toBeUndefined();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should return nothing if persisting not specified', async () => {
|
|
232
|
+
const result = await original.getCredentials(profile, auth);
|
|
233
|
+
|
|
234
|
+
expect(result).toBeUndefined();
|
|
235
|
+
});
|
|
200
236
|
});
|
|
201
237
|
|
|
202
238
|
describe('createCredentials', () => {
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import { google } from 'googleapis';
|
|
3
2
|
import auth from '../../auth';
|
|
4
|
-
import
|
|
5
|
-
import shared from '../shared';
|
|
6
|
-
import apiHelpers from './apiHelpers';
|
|
7
|
-
|
|
8
|
-
const original = jest.requireActual('../calendar').default as typeof calendar;
|
|
9
|
-
jest.mock<Partial<typeof calendar>>('../calendar', () => ({
|
|
10
|
-
getAPI : jest.fn().mockImplementation(async () => ({ calendarList : calendarsAPI, events : eventsAPI })),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
jest.mock<Partial<typeof shared>>('../shared', () => ({
|
|
14
|
-
getItems : jest.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
18
|
-
writeFileSync : jest.fn(),
|
|
19
|
-
}));
|
|
3
|
+
import { getAPI } from '../calendar';
|
|
20
4
|
|
|
21
5
|
jest.mock('googleapis', () => ({
|
|
22
6
|
google : {
|
|
23
|
-
calendar : jest.fn().mockImplementation(() =>
|
|
7
|
+
calendar : jest.fn().mockImplementation(() => api),
|
|
24
8
|
},
|
|
25
9
|
}));
|
|
26
10
|
|
|
@@ -28,136 +12,34 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
|
|
|
28
12
|
getAuth : jest.fn().mockImplementation(() => googleAuth),
|
|
29
13
|
}));
|
|
30
14
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const googleAuth = {
|
|
36
|
-
setCredentials : jest.fn(),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const calendars: Array<{ id?: string | null | undefined, summary?: string, description?: string, hidden?: boolean }> = [
|
|
40
|
-
{ id : 'id1', summary : 'calendar 1', description : 'calendar 1 description', hidden : false },
|
|
41
|
-
{ id : 'id2', summary : 'calendar 2', description : 'calendar 2 description', hidden : undefined },
|
|
42
|
-
{ id : null, summary : 'calendar 3', description : undefined, hidden : true },
|
|
43
|
-
{ id : 'id4', summary : 'calendar 4', description : undefined, hidden : undefined },
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
const calendarsResponse = [
|
|
47
|
-
[ calendars[0], calendars[1] ],
|
|
48
|
-
null,
|
|
49
|
-
[ calendars[2], calendars[3] ],
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
const events: Array<{ id?: string | null | undefined, summary?: string, source?: { url?: string, title?: string} }> = [
|
|
53
|
-
{ id : 'id1', summary : 'event 1', source : { title : 'source 1', url : 'https://example.com' } },
|
|
54
|
-
{ id : null, summary : 'event 2', source : { title : 'source 2', url : undefined } },
|
|
55
|
-
{ id : 'id3', summary : 'event 3', source : { title : undefined, url : undefined } },
|
|
56
|
-
{ id : 'id4', summary : 'event 4', source : undefined },
|
|
57
|
-
];
|
|
58
|
-
|
|
59
|
-
const eventsResponse = [
|
|
60
|
-
[ events[0], events[1] ],
|
|
61
|
-
null,
|
|
62
|
-
[ events[2], events[3] ],
|
|
63
|
-
];
|
|
64
|
-
|
|
65
|
-
const pageTokens = [
|
|
66
|
-
undefined,
|
|
67
|
-
'token1',
|
|
68
|
-
'token2',
|
|
69
|
-
];
|
|
70
|
-
|
|
71
|
-
const calendarsAPI = apiHelpers.getAPI(calendarsResponse, pageTokens);
|
|
72
|
-
const eventsAPI = apiHelpers.getAPI(eventsResponse, pageTokens);
|
|
15
|
+
const profile = 'username';
|
|
16
|
+
const api = 'api';
|
|
17
|
+
const googleAuth = 'googleAuth';
|
|
73
18
|
|
|
74
19
|
describe('src/lib/api/calendar', () => {
|
|
75
20
|
describe('getAPI', () => {
|
|
76
21
|
it('should call getAuth', async () => {
|
|
77
|
-
await
|
|
22
|
+
await getAPI(profile);
|
|
78
23
|
|
|
79
|
-
expect(auth.getAuth).toBeCalledWith(profile);
|
|
24
|
+
expect(auth.getAuth).toBeCalledWith(profile, undefined);
|
|
80
25
|
});
|
|
81
26
|
|
|
82
|
-
it('should
|
|
83
|
-
await
|
|
27
|
+
it('should pass persistence', async () => {
|
|
28
|
+
await getAPI(profile, { persist : true });
|
|
84
29
|
|
|
85
|
-
expect(
|
|
30
|
+
expect(auth.getAuth).toBeCalledWith(profile, { persist : true });
|
|
86
31
|
});
|
|
87
32
|
|
|
88
|
-
it('should
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
expect(result).toEqual({ calendarList : calendarsAPI, events : eventsAPI });
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('getCalendars', () => {
|
|
96
|
-
const args = { showHidden : true };
|
|
97
|
-
|
|
98
|
-
beforeEach(() => {
|
|
99
|
-
getItemsSpy.mockResolvedValue(calendars);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('should get api', async () => {
|
|
103
|
-
await original.getCalendars(profile, args);
|
|
104
|
-
|
|
105
|
-
expect(calendar.getAPI).toBeCalledWith(profile);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('should get items', async () => {
|
|
109
|
-
await original.getCalendars(profile, args);
|
|
110
|
-
|
|
111
|
-
expect(getItemsSpy).toBeCalledWith(calendarsAPI, args);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should return calendars', async () => {
|
|
115
|
-
const result = await original.getCalendars(profile, args);
|
|
116
|
-
|
|
117
|
-
expect(result).toEqual(calendars);
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
describe('getEvents', () => {
|
|
122
|
-
const args = { timeMin : '2010-01-01T00:00:00', timeMax : '2019-12-31T23:59:59' };
|
|
123
|
-
|
|
124
|
-
beforeEach(() => {
|
|
125
|
-
getItemsSpy.mockResolvedValue(events);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('should get api', async () => {
|
|
129
|
-
await original.getEvents(profile, args);
|
|
130
|
-
|
|
131
|
-
expect(calendar.getAPI).toBeCalledWith(profile);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('should get items', async () => {
|
|
135
|
-
await original.getEvents(profile, args);
|
|
136
|
-
|
|
137
|
-
expect(getItemsSpy).toBeCalledWith(eventsAPI, args);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should return events', async () => {
|
|
141
|
-
const result = await original.getEvents(profile, args);
|
|
142
|
-
|
|
143
|
-
expect(result).toEqual(events);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe('setEvent', () => {
|
|
148
|
-
const eventId = 'eventId';
|
|
149
|
-
const args = { requestBody : { summary : 'summary' } };
|
|
150
|
-
|
|
151
|
-
it('should get api', async () => {
|
|
152
|
-
await original.setEvent(profile, eventId, args);
|
|
33
|
+
it('should get calendar api', async () => {
|
|
34
|
+
await getAPI(profile);
|
|
153
35
|
|
|
154
|
-
expect(calendar
|
|
36
|
+
expect(google.calendar).toBeCalledWith({ version : 'v3', auth : googleAuth });
|
|
155
37
|
});
|
|
156
38
|
|
|
157
|
-
it('should
|
|
158
|
-
await
|
|
39
|
+
it('should return calendar api', async () => {
|
|
40
|
+
const result = await getAPI(profile);
|
|
159
41
|
|
|
160
|
-
expect(
|
|
42
|
+
expect(result).toEqual(api);
|
|
161
43
|
});
|
|
162
44
|
});
|
|
163
45
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import logger from '../../logger';
|
|
2
2
|
import sleep from '../../sleep';
|
|
3
3
|
import shared from '../shared';
|
|
4
|
-
import apiHelpers from './apiHelpers';
|
|
5
4
|
|
|
6
5
|
const original = jest.requireActual('../shared').default as typeof shared;
|
|
7
6
|
jest.mock<Partial<typeof shared>>('../shared', () => ({
|
|
@@ -35,7 +34,24 @@ const pageTokens = [
|
|
|
35
34
|
'token2',
|
|
36
35
|
];
|
|
37
36
|
|
|
38
|
-
const
|
|
37
|
+
const getAPI = <T>(items: Array<Array<T> | null>, pageTokens: Array<string | undefined>) => ({
|
|
38
|
+
list : jest.fn().mockImplementation(async ({ pageToken }: {pageToken?: string}) => {
|
|
39
|
+
const index = pageTokens.indexOf(pageToken);
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
data : {
|
|
43
|
+
items : items[index],
|
|
44
|
+
nextPageToken : pageTokens[index + 1],
|
|
45
|
+
pageInfo : !items[index] ? null : {
|
|
46
|
+
totalResults : items.reduce((sum, list) => sum + (list?.length || 0), 0),
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
}),
|
|
51
|
+
update : jest.fn(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const api = getAPI(response, pageTokens);
|
|
39
55
|
const args = { key : 'value' };
|
|
40
56
|
|
|
41
57
|
describe('src/lib/api/shared', () => {
|
|
@@ -49,7 +65,7 @@ describe('src/lib/api/shared', () => {
|
|
|
49
65
|
});
|
|
50
66
|
|
|
51
67
|
it('should output progress if requested', async () => {
|
|
52
|
-
await original.getItems(api, args, true);
|
|
68
|
+
await original.getItems(api, args, { showProgress : true });
|
|
53
69
|
|
|
54
70
|
expect(logger.log).toBeCalledTimes(response.length);
|
|
55
71
|
expect(logger.log).toBeCalledWith('Getting items (2 of 4)...');
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
1
|
import { google } from 'googleapis';
|
|
3
2
|
import auth from '../../auth';
|
|
4
|
-
import
|
|
5
|
-
import shared from '../shared';
|
|
6
|
-
import apiHelpers from './apiHelpers';
|
|
7
|
-
|
|
8
|
-
const original = jest.requireActual('../youtube').default as typeof youtube;
|
|
9
|
-
jest.mock<Partial<typeof youtube>>('../youtube', () => ({
|
|
10
|
-
getAPI : jest.fn().mockImplementation(async () => ({ playlistItems : playlistItemsAPI })),
|
|
11
|
-
}));
|
|
12
|
-
|
|
13
|
-
jest.mock<Partial<typeof shared>>('../shared', () => ({
|
|
14
|
-
getItems : jest.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
jest.mock<Partial<typeof fs>>('fs', () => ({
|
|
18
|
-
writeFileSync : jest.fn(),
|
|
19
|
-
}));
|
|
3
|
+
import { getAPI } from '../youtube';
|
|
20
4
|
|
|
21
5
|
jest.mock('googleapis', () => ({
|
|
22
6
|
google : {
|
|
23
|
-
youtube : jest.fn().mockImplementation(() =>
|
|
7
|
+
youtube : jest.fn().mockImplementation(() => api),
|
|
24
8
|
},
|
|
25
9
|
}));
|
|
26
10
|
|
|
@@ -28,79 +12,34 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
|
|
|
28
12
|
getAuth : jest.fn().mockImplementation(() => googleAuth),
|
|
29
13
|
}));
|
|
30
14
|
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const googleAuth = {
|
|
36
|
-
setCredentials : jest.fn(),
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const playlistItems: Array<{ id?: string | null | undefined, snippet?: { title?: string, resourceId?: { videoId?: string } } }> = [
|
|
40
|
-
{ id : 'id1', snippet : { title : 'video1', resourceId : { videoId : 'video1Id' } } },
|
|
41
|
-
{ id : null, snippet : { title : 'video2', resourceId : { videoId : undefined } } },
|
|
42
|
-
{ id : 'id3', snippet : { title : undefined, resourceId : undefined } },
|
|
43
|
-
{ id : 'id4', snippet : undefined },
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
const playlistItemsResponse = [
|
|
47
|
-
[ playlistItems[0], playlistItems[1] ],
|
|
48
|
-
null,
|
|
49
|
-
[ playlistItems[2], playlistItems[3] ],
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
const pageTokens = [
|
|
53
|
-
undefined,
|
|
54
|
-
'token1',
|
|
55
|
-
'token2',
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
const playlistItemsAPI = apiHelpers.getAPI(playlistItemsResponse, pageTokens);
|
|
15
|
+
const profile = 'username';
|
|
16
|
+
const api = 'api';
|
|
17
|
+
const googleAuth = 'googleAuth';
|
|
59
18
|
|
|
60
19
|
describe('src/lib/api/youtube', () => {
|
|
61
20
|
describe('getAPI', () => {
|
|
62
21
|
it('should call getAuth', async () => {
|
|
63
|
-
await
|
|
64
|
-
|
|
65
|
-
expect(auth.getAuth).toBeCalledWith(profile);
|
|
66
|
-
});
|
|
22
|
+
await getAPI(profile);
|
|
67
23
|
|
|
68
|
-
|
|
69
|
-
await original.getAPI(profile);
|
|
70
|
-
|
|
71
|
-
expect(google.youtube).toBeCalledWith({ version : 'v3', auth : googleAuth });
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should return youtube api', async () => {
|
|
75
|
-
const result = await original.getAPI(profile);
|
|
76
|
-
|
|
77
|
-
expect(result).toEqual({ playlistItems : playlistItemsAPI });
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('getPlaylistItems', () => {
|
|
82
|
-
const args = { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 };
|
|
83
|
-
|
|
84
|
-
beforeEach(() => {
|
|
85
|
-
getItemsSpy.mockResolvedValue(playlistItems);
|
|
24
|
+
expect(auth.getAuth).toBeCalledWith(profile, undefined);
|
|
86
25
|
});
|
|
87
26
|
|
|
88
|
-
it('should
|
|
89
|
-
await
|
|
27
|
+
it('should pass persistence', async () => {
|
|
28
|
+
await getAPI(profile, { persist : true });
|
|
90
29
|
|
|
91
|
-
expect(
|
|
30
|
+
expect(auth.getAuth).toBeCalledWith(profile, { persist : true });
|
|
92
31
|
});
|
|
93
32
|
|
|
94
|
-
it('should
|
|
95
|
-
await
|
|
33
|
+
it('should get youtube api', async () => {
|
|
34
|
+
await getAPI(profile);
|
|
96
35
|
|
|
97
|
-
expect(
|
|
36
|
+
expect(google.youtube).toBeCalledWith({ version : 'v3', auth : googleAuth });
|
|
98
37
|
});
|
|
99
38
|
|
|
100
|
-
it('should return
|
|
101
|
-
const result = await
|
|
39
|
+
it('should return youtube api', async () => {
|
|
40
|
+
const result = await getAPI(profile);
|
|
102
41
|
|
|
103
|
-
expect(result).toEqual(
|
|
42
|
+
expect(result).toEqual(api);
|
|
104
43
|
});
|
|
105
44
|
});
|
|
106
45
|
});
|
package/src/lib/api/calendar.ts
CHANGED
|
@@ -1,32 +1,13 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import type GoogleApis from 'googleapis';
|
|
3
|
+
import type { AuthOptions } from '../../types';
|
|
3
4
|
import { getAuth } from '../auth';
|
|
4
|
-
import { getItems } from './shared';
|
|
5
|
-
import calendar from './calendar';
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar> {
|
|
11
|
-
const googleAuth = await getAuth(profile);
|
|
6
|
+
export async function getAPI(profile: string, options?: AuthOptions): Promise<GoogleApis.calendar_v3.Calendar> {
|
|
7
|
+
const googleAuth = await getAuth(profile, options);
|
|
12
8
|
|
|
13
9
|
return google.calendar({
|
|
14
10
|
version : 'v3',
|
|
15
11
|
auth : googleAuth,
|
|
16
12
|
});
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
async function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List): Promise<GoogleApis.calendar_v3.Schema$CalendarListEntry[]> {
|
|
20
|
-
const api = await calendar.getAPI(profile);
|
|
21
|
-
return getItems(api.calendarList, args);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<GoogleApis.calendar_v3.Schema$Event[]> {
|
|
25
|
-
const api = await calendar.getAPI(profile);
|
|
26
|
-
return getItems(api.events, args);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function setEvent(profile: string, eventId: string | undefined, args: GoogleApis.calendar_v3.Params$Resource$Events$Update) {
|
|
30
|
-
const api = await calendar.getAPI(profile);
|
|
31
|
-
api.events.update({ eventId, ...args });
|
|
32
|
-
}
|
package/src/lib/api/shared.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { GetItemsOptions } from '../../types';
|
|
2
3
|
import { log } from '../logger';
|
|
3
4
|
import { sleep } from '../sleep';
|
|
4
5
|
|
|
@@ -27,7 +28,7 @@ async function getItems<
|
|
|
27
28
|
TItem,
|
|
28
29
|
TArgs,
|
|
29
30
|
TResponse extends CommonResponse<TItem>
|
|
30
|
-
>(api: TApi, args: TArgs,
|
|
31
|
+
>(api: TApi, args: TArgs, options?: GetItemsOptions): Promise<TItem[]> {
|
|
31
32
|
const items: TItem[] = [];
|
|
32
33
|
|
|
33
34
|
let pageToken: string | null | undefined = undefined;
|
|
@@ -36,7 +37,7 @@ async function getItems<
|
|
|
36
37
|
const response: GoogleApis.Common.GaxiosResponse<TResponse> = await api.list({ ...args, pageToken });
|
|
37
38
|
response.data.items?.forEach((item) => items.push(item));
|
|
38
39
|
|
|
39
|
-
if (showProgress) {
|
|
40
|
+
if (options?.showProgress) {
|
|
40
41
|
log(`Getting items (${items.length} of ${response.data.pageInfo?.totalResults || 'many'})...`);
|
|
41
42
|
}
|
|
42
43
|
|
package/src/lib/api/youtube.ts
CHANGED
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import type GoogleApis from 'googleapis';
|
|
3
|
+
import type { AuthOptions } from '../../types';
|
|
3
4
|
import { getAuth } from '../auth';
|
|
4
|
-
import { getItems } from './shared';
|
|
5
|
-
import youtube from './youtube';
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
async function getAPI(profile: string): Promise<GoogleApis.youtube_v3.Youtube> {
|
|
11
|
-
const googleAuth = await getAuth(profile);
|
|
6
|
+
export async function getAPI(profile: string, options?: AuthOptions): Promise<GoogleApis.youtube_v3.Youtube> {
|
|
7
|
+
const googleAuth = await getAuth(profile, options);
|
|
12
8
|
|
|
13
9
|
return google.youtube({
|
|
14
10
|
version : 'v3',
|
|
15
11
|
auth : googleAuth,
|
|
16
12
|
});
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
async function getPlaylistItems(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]> {
|
|
20
|
-
const api = await youtube.getAPI(profile);
|
|
21
|
-
return getItems(api.playlistItems, args);
|
|
22
|
-
}
|
package/src/lib/auth.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import type GoogleApis from 'googleapis';
|
|
3
|
+
import type { AuthOptions } from '../types';
|
|
3
4
|
import { info, warn } from './logger';
|
|
4
5
|
import { getProfiles } from './profiles';
|
|
5
6
|
import { getCredentials, getSecrets } from './secrets';
|
|
@@ -14,12 +15,12 @@ async function login(profile?: string): Promise<void> {
|
|
|
14
15
|
|
|
15
16
|
for (const profile of profiles) {
|
|
16
17
|
warn(`${profile} - logging in...`);
|
|
17
|
-
await auth.getAuth(profile);
|
|
18
|
+
await auth.getAuth(profile, { persist : true });
|
|
18
19
|
info(`${profile} - logged in successfully`);
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
async function getAuth(profile: string): Promise<GoogleApis.Common.OAuth2Client> {
|
|
23
|
+
async function getAuth(profile: string, options?: AuthOptions): Promise<GoogleApis.Common.OAuth2Client> {
|
|
23
24
|
const secrets = getSecrets(profile);
|
|
24
25
|
|
|
25
26
|
const googleAuth = new google.auth.OAuth2(
|
|
@@ -28,7 +29,7 @@ async function getAuth(profile: string): Promise<GoogleApis.Common.OAuth2Client>
|
|
|
28
29
|
secrets.web.redirect_uris[0],
|
|
29
30
|
);
|
|
30
31
|
|
|
31
|
-
const tokens = await getCredentials(profile, googleAuth);
|
|
32
|
+
const tokens = await getCredentials(profile, googleAuth, options);
|
|
32
33
|
googleAuth.setCredentials(tokens);
|
|
33
34
|
return googleAuth;
|
|
34
35
|
}
|
package/src/lib/secrets.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import http from 'http';
|
|
2
2
|
import * as colorette from 'colorette';
|
|
3
3
|
import type GoogleApis from 'googleapis';
|
|
4
|
-
import type { Secrets } from '../types';
|
|
4
|
+
import type { Secrets, AuthOptions } from '../types';
|
|
5
5
|
import { getJSON, getJSONAsync } from './jsonLib';
|
|
6
6
|
import { info, error } from './logger';
|
|
7
7
|
import { getScopesFile, getSecretsFile, getCredentialsFile } from './paths';
|
|
@@ -27,9 +27,12 @@ function getSecrets(profile: string): Secrets {
|
|
|
27
27
|
return secretsObject;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
async function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client): Promise<GoogleApis.Auth.Credentials> {
|
|
30
|
+
async function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials> {
|
|
31
31
|
const credentialsFile = getCredentialsFile(profile);
|
|
32
|
-
|
|
32
|
+
|
|
33
|
+
return options?.persist
|
|
34
|
+
? getJSONAsync(credentialsFile, () => secrets.createCredentials(profile, auth))
|
|
35
|
+
: secrets.createCredentials(profile, auth);
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
async function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client): Promise<GoogleApis.Auth.Credentials> {
|
package/src/types/api.ts
ADDED
package/src/types/index.ts
CHANGED
package/src/types/secrets.ts
CHANGED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const getAPI = <T>(items: Array<Array<T> | null>, pageTokens: Array<string | undefined>) => ({
|
|
2
|
-
list : jest.fn().mockImplementation(async ({ pageToken }: {pageToken?: string}) => {
|
|
3
|
-
const index = pageTokens.indexOf(pageToken);
|
|
4
|
-
|
|
5
|
-
return {
|
|
6
|
-
data : {
|
|
7
|
-
items : items[index],
|
|
8
|
-
nextPageToken : pageTokens[index + 1],
|
|
9
|
-
pageInfo : !items[index] ? null : {
|
|
10
|
-
totalResults : items.reduce((sum, list) => sum + (list?.length || 0), 0),
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}),
|
|
15
|
-
update : jest.fn(),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
export default { getAPI };
|