@anmiles/google-api-wrapper 7.0.6 → 7.0.7
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/.eslintrc.js +1 -86
- package/.gitlab-ci.yml +0 -1
- package/.vscode/settings.json +0 -4
- package/CHANGELOG.md +7 -0
- package/README.md +5 -2
- package/dist/index.d.ts +5 -5
- package/dist/index.js +15 -15
- package/dist/lib/api/calendar.d.ts +3 -3
- package/dist/lib/api/calendar.js +13 -13
- package/dist/lib/api/shared.d.ts +23 -23
- package/dist/lib/api/shared.js +23 -23
- package/dist/lib/api/shared.js.map +1 -1
- package/dist/lib/api/youtube.d.ts +3 -3
- package/dist/lib/api/youtube.js +13 -13
- package/dist/lib/auth.d.ts +10 -10
- package/dist/lib/auth.js +34 -34
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/jsonLib.d.ts +14 -14
- package/dist/lib/jsonLib.js +54 -55
- package/dist/lib/jsonLib.js.map +1 -1
- package/dist/lib/paths.d.ts +16 -16
- package/dist/lib/paths.js +45 -45
- package/dist/lib/profiles.d.ts +10 -10
- package/dist/lib/profiles.js +32 -33
- package/dist/lib/profiles.js.map +1 -1
- package/dist/lib/secrets.d.ts +22 -22
- package/dist/lib/secrets.js +150 -146
- package/dist/lib/secrets.js.map +1 -1
- package/dist/lib/sleep.d.ts +6 -6
- package/dist/lib/sleep.js +10 -10
- package/dist/types/common.d.ts +3 -3
- package/dist/types/common.js +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +18 -18
- package/dist/types/secrets.d.ts +15 -15
- package/dist/types/secrets.js +2 -2
- package/package.json +16 -15
- package/src/lib/__tests__/auth.test.ts +23 -23
- package/src/lib/__tests__/jsonLib.test.ts +33 -41
- package/src/lib/__tests__/paths.test.ts +5 -5
- package/src/lib/__tests__/profiles.test.ts +10 -13
- package/src/lib/__tests__/secrets.test.ts +40 -48
- package/src/lib/api/__tests__/calendar.test.ts +3 -3
- package/src/lib/api/__tests__/shared.test.ts +10 -10
- package/src/lib/api/__tests__/youtube.test.ts +3 -3
- package/src/lib/api/shared.ts +1 -1
- package/src/lib/auth.ts +1 -1
- package/src/lib/jsonLib.ts +2 -2
- package/src/lib/profiles.ts +1 -2
- package/src/lib/secrets.ts +8 -4
- package/dist/lib/logger.d.ts +0 -12
- package/dist/lib/logger.js +0 -46
- package/dist/lib/logger.js.map +0 -1
- package/src/lib/__tests__/logger.test.ts +0 -57
- package/src/lib/logger.ts +0 -21
package/.eslintrc.js
CHANGED
|
@@ -1,91 +1,6 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
root : true,
|
|
3
3
|
extends : [
|
|
4
|
-
'eslint
|
|
5
|
-
'plugin:jest/recommended',
|
|
4
|
+
'./node_modules/@anmiles/eslint-config/.eslintrc.js',
|
|
6
5
|
],
|
|
7
|
-
parser : '@typescript-eslint/parser',
|
|
8
|
-
parserOptions : {
|
|
9
|
-
ecmaVersion : 2019,
|
|
10
|
-
sourceType : 'module',
|
|
11
|
-
},
|
|
12
|
-
plugins : [
|
|
13
|
-
'@typescript-eslint',
|
|
14
|
-
'align-assignments',
|
|
15
|
-
'import',
|
|
16
|
-
'jest',
|
|
17
|
-
],
|
|
18
|
-
env : {
|
|
19
|
-
node : true,
|
|
20
|
-
jest : true,
|
|
21
|
-
},
|
|
22
|
-
ignorePatterns : [
|
|
23
|
-
'**/node_modules/',
|
|
24
|
-
'coverage/',
|
|
25
|
-
'dist/',
|
|
26
|
-
],
|
|
27
|
-
rules : {
|
|
28
|
-
'no-unused-vars' : [ 'off' ],
|
|
29
|
-
'@typescript-eslint/no-unused-vars' : [ 'error' ],
|
|
30
|
-
'align-assignments/align-assignments' : [ 'error' ],
|
|
31
|
-
'array-bracket-spacing' : [ 'error', 'always' ],
|
|
32
|
-
'arrow-body-style' : [ 'error' ],
|
|
33
|
-
'arrow-parens' : [ 'error' ],
|
|
34
|
-
'arrow-spacing' : [ 'error' ],
|
|
35
|
-
'block-spacing' : [ 'error' ],
|
|
36
|
-
'brace-style' : [ 'error' ],
|
|
37
|
-
'camelcase' : [ 'error' ],
|
|
38
|
-
'comma-dangle' : [ 'error', 'always-multiline' ],
|
|
39
|
-
'comma-spacing' : [ 'error' ],
|
|
40
|
-
'comma-style' : [ 'error' ],
|
|
41
|
-
'complexity' : [ 'error' ],
|
|
42
|
-
'computed-property-spacing' : [ 'error', 'never' ],
|
|
43
|
-
'curly' : [ 'error' ],
|
|
44
|
-
'dot-location' : [ 'error', 'property' ],
|
|
45
|
-
'eol-last' : [ 'error' ],
|
|
46
|
-
'func-call-spacing' : [ 'error' ],
|
|
47
|
-
'func-style' : [ 'error', 'declaration', { allowArrowFunctions : true } ],
|
|
48
|
-
'generator-star-spacing' : [ 'error', 'neither' ],
|
|
49
|
-
'import/order' : [ 'error', { groups : [ 'builtin', 'external', 'unknown', 'internal', 'parent', 'sibling', 'index' ] } ],
|
|
50
|
-
'indent' : [ 'error', 'tab', { SwitchCase : 1 } ],
|
|
51
|
-
'jest/no-standalone-expect' : [ 'error' ],
|
|
52
|
-
'key-spacing' : [ 'error', { beforeColon : true, afterColon : true, align : 'colon' } ],
|
|
53
|
-
'keyword-spacing' : [ 'error' ],
|
|
54
|
-
'linebreak-style' : [ 'error', 'unix' ],
|
|
55
|
-
'max-params' : [ 'error', { max : 5 } ],
|
|
56
|
-
'new-parens' : [ 'error' ],
|
|
57
|
-
'no-eval' : [ 'error' ],
|
|
58
|
-
'no-extra-bind' : [ 'error' ],
|
|
59
|
-
'no-floating-decimal' : [ 'error' ],
|
|
60
|
-
'no-implied-eval' : [ 'error' ],
|
|
61
|
-
'no-loop-func' : [ 'error' ],
|
|
62
|
-
'no-mixed-spaces-and-tabs' : [ 'error', 'smart-tabs' ],
|
|
63
|
-
'no-multiple-empty-lines' : [ 'error', { max : 1, maxEOF : 1, maxBOF : 0 } ],
|
|
64
|
-
'no-return-await' : [ 'error' ],
|
|
65
|
-
'no-trailing-spaces' : [ 'error' ],
|
|
66
|
-
'no-useless-rename' : [ 'error' ],
|
|
67
|
-
'no-var' : [ 'error' ],
|
|
68
|
-
'no-whitespace-before-property' : [ 'error' ],
|
|
69
|
-
'object-curly-spacing' : [ 'error', 'always' ],
|
|
70
|
-
'object-property-newline' : [ 'error', { allowMultiplePropertiesPerLine : true } ],
|
|
71
|
-
'object-shorthand' : [ 'error' ],
|
|
72
|
-
'operator-linebreak' : [ 'error', 'before' ],
|
|
73
|
-
'prefer-const' : [ 'error' ],
|
|
74
|
-
'prefer-numeric-literals' : [ 'error' ],
|
|
75
|
-
'prefer-spread' : [ 'error' ],
|
|
76
|
-
'prefer-template' : [ 'error' ],
|
|
77
|
-
'quote-props' : [ 'error', 'consistent-as-needed' ],
|
|
78
|
-
'quotes' : [ 'error', 'single', { avoidEscape : true } ],
|
|
79
|
-
'semi-spacing' : [ 'error' ],
|
|
80
|
-
'semi' : [ 'error' ],
|
|
81
|
-
'space-before-blocks' : [ 'error' ],
|
|
82
|
-
'space-before-function-paren' : [ 'error', { anonymous : 'never', named : 'never', asyncArrow : 'always' } ],
|
|
83
|
-
'space-in-parens' : [ 'error' ],
|
|
84
|
-
'space-infix-ops' : [ 'error' ],
|
|
85
|
-
'space-unary-ops' : [ 'error' ],
|
|
86
|
-
'spaced-comment' : [ 'error' ],
|
|
87
|
-
'template-curly-spacing' : [ 'error' ],
|
|
88
|
-
'yield-star-spacing' : [ 'error' ],
|
|
89
|
-
'yoda' : [ 'error' ],
|
|
90
|
-
},
|
|
91
6
|
};
|
package/.gitlab-ci.yml
CHANGED
package/.vscode/settings.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,13 @@ 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
|
+
## [7.0.7](../../tags/v7.0.7) - 2023-05-07
|
|
9
|
+
### Changed
|
|
10
|
+
- Move repository
|
|
11
|
+
- Use shared eslint config
|
|
12
|
+
- Use `@anmiles/logger` instead of old built-in logger
|
|
13
|
+
- Cleanup cSpell words
|
|
14
|
+
|
|
8
15
|
## [7.0.6](../../tags/v7.0.6) - 2023-05-02
|
|
9
16
|
### Changed
|
|
10
17
|
- Display scopes on instructions page
|
package/README.md
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
# google-api-wrapper
|
|
1
|
+
# @anmiles/google-api-wrapper
|
|
2
2
|
|
|
3
3
|
Provides quick interface for getting google API data
|
|
4
4
|
|
|
5
5
|
----
|
|
6
6
|
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
`npm install @anmiles/google-api-wrapper`
|
|
10
|
+
|
|
7
11
|
## Usage
|
|
8
12
|
|
|
9
13
|
``` bash
|
|
10
|
-
> $ npm install @anmiles/google-api-wrapper
|
|
11
14
|
> $ node ./auth.js
|
|
12
15
|
> $ node ./videos.js
|
|
13
16
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { getAPI as getCalendarAPI } from './lib/api/calendar';
|
|
2
|
-
export { getAPI as getYoutubeAPI } from './lib/api/youtube';
|
|
3
|
-
export { getItems } from './lib/api/shared';
|
|
4
|
-
export { createProfile, getProfiles } from './lib/profiles';
|
|
5
|
-
export { login, getAuth } from './lib/auth';
|
|
1
|
+
export { getAPI as getCalendarAPI } from './lib/api/calendar';
|
|
2
|
+
export { getAPI as getYoutubeAPI } from './lib/api/youtube';
|
|
3
|
+
export { getItems } from './lib/api/shared';
|
|
4
|
+
export { createProfile, getProfiles } from './lib/profiles';
|
|
5
|
+
export { login, getAuth } from './lib/auth';
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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; } });
|
|
8
|
-
var shared_1 = require("./lib/api/shared");
|
|
9
|
-
Object.defineProperty(exports, "getItems", { enumerable: true, get: function () { return shared_1.getItems; } });
|
|
10
|
-
var profiles_1 = require("./lib/profiles");
|
|
11
|
-
Object.defineProperty(exports, "createProfile", { enumerable: true, get: function () { return profiles_1.createProfile; } });
|
|
12
|
-
Object.defineProperty(exports, "getProfiles", { enumerable: true, get: function () { return profiles_1.getProfiles; } });
|
|
13
|
-
var auth_1 = require("./lib/auth");
|
|
14
|
-
Object.defineProperty(exports, "login", { enumerable: true, get: function () { return auth_1.login; } });
|
|
15
|
-
Object.defineProperty(exports, "getAuth", { enumerable: true, get: function () { return auth_1.getAuth; } });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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; } });
|
|
8
|
+
var shared_1 = require("./lib/api/shared");
|
|
9
|
+
Object.defineProperty(exports, "getItems", { enumerable: true, get: function () { return shared_1.getItems; } });
|
|
10
|
+
var profiles_1 = require("./lib/profiles");
|
|
11
|
+
Object.defineProperty(exports, "createProfile", { enumerable: true, get: function () { return profiles_1.createProfile; } });
|
|
12
|
+
Object.defineProperty(exports, "getProfiles", { enumerable: true, get: function () { return profiles_1.getProfiles; } });
|
|
13
|
+
var auth_1 = require("./lib/auth");
|
|
14
|
+
Object.defineProperty(exports, "login", { enumerable: true, get: function () { return auth_1.login; } });
|
|
15
|
+
Object.defineProperty(exports, "getAuth", { enumerable: true, get: function () { return auth_1.getAuth; } });
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { AuthOptions } from '../../types';
|
|
3
|
-
export declare function getAPI(profile: string, options?: AuthOptions): Promise<GoogleApis.calendar_v3.Calendar>;
|
|
1
|
+
import type GoogleApis from 'googleapis';
|
|
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,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAPI = void 0;
|
|
4
|
-
const googleapis_1 = require("googleapis");
|
|
5
|
-
const auth_1 = require("../auth");
|
|
6
|
-
async function getAPI(profile, options) {
|
|
7
|
-
const googleAuth = await (0, auth_1.getAuth)(profile, options);
|
|
8
|
-
return googleapis_1.google.calendar({
|
|
9
|
-
version: 'v3',
|
|
10
|
-
auth: googleAuth,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
exports.getAPI = getAPI;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAPI = void 0;
|
|
4
|
+
const googleapis_1 = require("googleapis");
|
|
5
|
+
const auth_1 = require("../auth");
|
|
6
|
+
async function getAPI(profile, options) {
|
|
7
|
+
const googleAuth = await (0, auth_1.getAuth)(profile, options);
|
|
8
|
+
return googleapis_1.google.calendar({
|
|
9
|
+
version: 'v3',
|
|
10
|
+
auth: googleAuth,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.getAPI = getAPI;
|
|
14
14
|
//# sourceMappingURL=calendar.js.map
|
package/dist/lib/api/shared.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { CommonOptions } from '../../types';
|
|
3
|
-
export { getItems };
|
|
4
|
-
declare const _default: {
|
|
5
|
-
getItems: typeof getItems;
|
|
6
|
-
};
|
|
7
|
-
export default _default;
|
|
8
|
-
type CommonApi<TItem> = {
|
|
9
|
-
list: {
|
|
10
|
-
(params?: {
|
|
11
|
-
pageToken: string | undefined;
|
|
12
|
-
}, options?: GoogleApis.Common.MethodOptions): Promise<GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>>>;
|
|
13
|
-
(callback: (err: Error | null, res?: GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>> | null) => void): void;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
type CommonResponse<TItem> = {
|
|
17
|
-
items?: TItem[];
|
|
18
|
-
pageInfo?: {
|
|
19
|
-
totalResults?: number | null | undefined;
|
|
20
|
-
};
|
|
21
|
-
nextPageToken?: string | null | undefined;
|
|
22
|
-
};
|
|
23
|
-
declare function getItems<TItem>(api: CommonApi<TItem>, params: any, options?: CommonOptions): Promise<TItem[]>;
|
|
1
|
+
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { CommonOptions } from '../../types';
|
|
3
|
+
export { getItems };
|
|
4
|
+
declare const _default: {
|
|
5
|
+
getItems: typeof getItems;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
type CommonApi<TItem> = {
|
|
9
|
+
list: {
|
|
10
|
+
(params?: {
|
|
11
|
+
pageToken: string | undefined;
|
|
12
|
+
}, options?: GoogleApis.Common.MethodOptions): Promise<GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>>>;
|
|
13
|
+
(callback: (err: Error | null, res?: GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>> | null) => void): void;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
type CommonResponse<TItem> = {
|
|
17
|
+
items?: TItem[];
|
|
18
|
+
pageInfo?: {
|
|
19
|
+
totalResults?: number | null | undefined;
|
|
20
|
+
};
|
|
21
|
+
nextPageToken?: string | null | undefined;
|
|
22
|
+
};
|
|
23
|
+
declare function getItems<TItem>(api: CommonApi<TItem>, params: any, options?: CommonOptions): Promise<TItem[]>;
|
package/dist/lib/api/shared.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getItems = void 0;
|
|
4
|
-
const logger_1 = require("
|
|
5
|
-
const sleep_1 = require("../sleep");
|
|
6
|
-
exports.default = { getItems };
|
|
7
|
-
const requestInterval = 300;
|
|
8
|
-
async function getItems(api, params, options) {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
const items = [];
|
|
11
|
-
let pageToken = undefined;
|
|
12
|
-
do {
|
|
13
|
-
const response = await api.list({ ...params, pageToken });
|
|
14
|
-
(_a = response.data.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => items.push(item));
|
|
15
|
-
if (!(options === null || options === void 0 ? void 0 : options.hideProgress)) {
|
|
16
|
-
(0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
|
|
17
|
-
}
|
|
18
|
-
await (0, sleep_1.sleep)(requestInterval);
|
|
19
|
-
pageToken = response.data.nextPageToken;
|
|
20
|
-
} while (pageToken);
|
|
21
|
-
return items;
|
|
22
|
-
}
|
|
23
|
-
exports.getItems = getItems;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getItems = void 0;
|
|
4
|
+
const logger_1 = require("@anmiles/logger");
|
|
5
|
+
const sleep_1 = require("../sleep");
|
|
6
|
+
exports.default = { getItems };
|
|
7
|
+
const requestInterval = 300;
|
|
8
|
+
async function getItems(api, params, options) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const items = [];
|
|
11
|
+
let pageToken = undefined;
|
|
12
|
+
do {
|
|
13
|
+
const response = await api.list({ ...params, pageToken });
|
|
14
|
+
(_a = response.data.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => items.push(item));
|
|
15
|
+
if (!(options === null || options === void 0 ? void 0 : options.hideProgress)) {
|
|
16
|
+
(0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
|
|
17
|
+
}
|
|
18
|
+
await (0, sleep_1.sleep)(requestInterval);
|
|
19
|
+
pageToken = response.data.nextPageToken;
|
|
20
|
+
} while (pageToken);
|
|
21
|
+
return items;
|
|
22
|
+
}
|
|
23
|
+
exports.getItems = getItems;
|
|
24
24
|
//# sourceMappingURL=shared.js.map
|
|
@@ -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":";;;AACA,4CAAsC;AAEtC,oCAAiC;AAGjC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAE5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAiB5B,KAAK,UAAU,QAAQ,CAAQ,GAAqB,EAAE,MAAW,EAAE,OAAuB;;IACzF,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAA4D,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QACnH,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAA,EAAE;YAC3B,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,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;QAC7B,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;KACxC,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AAtCQ,4BAAQ"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { AuthOptions } from '../../types';
|
|
3
|
-
export declare function getAPI(profile: string, options?: AuthOptions): Promise<GoogleApis.youtube_v3.Youtube>;
|
|
1
|
+
import type GoogleApis from 'googleapis';
|
|
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,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAPI = void 0;
|
|
4
|
-
const googleapis_1 = require("googleapis");
|
|
5
|
-
const auth_1 = require("../auth");
|
|
6
|
-
async function getAPI(profile, options) {
|
|
7
|
-
const googleAuth = await (0, auth_1.getAuth)(profile, options);
|
|
8
|
-
return googleapis_1.google.youtube({
|
|
9
|
-
version: 'v3',
|
|
10
|
-
auth: googleAuth,
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
exports.getAPI = getAPI;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAPI = void 0;
|
|
4
|
+
const googleapis_1 = require("googleapis");
|
|
5
|
+
const auth_1 = require("../auth");
|
|
6
|
+
async function getAPI(profile, options) {
|
|
7
|
+
const googleAuth = await (0, auth_1.getAuth)(profile, options);
|
|
8
|
+
return googleapis_1.google.youtube({
|
|
9
|
+
version: 'v3',
|
|
10
|
+
auth: googleAuth,
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
exports.getAPI = getAPI;
|
|
14
14
|
//# sourceMappingURL=youtube.js.map
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { CommonOptions, AuthOptions } from '../types';
|
|
3
|
-
export { login, getAuth };
|
|
4
|
-
declare const _default: {
|
|
5
|
-
login: typeof login;
|
|
6
|
-
getAuth: typeof getAuth;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
9
|
-
declare function login(profile?: string, options?: CommonOptions & AuthOptions): Promise<void>;
|
|
10
|
-
declare function getAuth(profile: string, options?: AuthOptions): Promise<GoogleApis.Common.OAuth2Client>;
|
|
1
|
+
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { CommonOptions, AuthOptions } from '../types';
|
|
3
|
+
export { login, getAuth };
|
|
4
|
+
declare const _default: {
|
|
5
|
+
login: typeof login;
|
|
6
|
+
getAuth: typeof getAuth;
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
declare function login(profile?: string, options?: CommonOptions & AuthOptions): Promise<void>;
|
|
10
|
+
declare function getAuth(profile: string, options?: AuthOptions): Promise<GoogleApis.Common.OAuth2Client>;
|
package/dist/lib/auth.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAuth = exports.login = void 0;
|
|
7
|
-
const googleapis_1 = require("googleapis");
|
|
8
|
-
const logger_1 = require("
|
|
9
|
-
const profiles_1 = require("./profiles");
|
|
10
|
-
const secrets_1 = require("./secrets");
|
|
11
|
-
const auth_1 = __importDefault(require("./auth"));
|
|
12
|
-
exports.default = { login, getAuth };
|
|
13
|
-
async function login(profile, options) {
|
|
14
|
-
const profiles = (0, profiles_1.getProfiles)().filter((p) => !profile || p === profile);
|
|
15
|
-
for (const profile of profiles) {
|
|
16
|
-
if (!(options === null || options === void 0 ? void 0 : options.hideProgress)) {
|
|
17
|
-
(0, logger_1.warn)(`${profile} - logging in...`);
|
|
18
|
-
}
|
|
19
|
-
await auth_1.default.getAuth(profile, options);
|
|
20
|
-
if (!(options === null || options === void 0 ? void 0 : options.hideProgress)) {
|
|
21
|
-
(0, logger_1.info)(`${profile} - logged in successfully`);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.login = login;
|
|
26
|
-
async function getAuth(profile, options) {
|
|
27
|
-
const secrets = (0, secrets_1.getSecrets)(profile);
|
|
28
|
-
const googleAuth = new googleapis_1.google.auth.OAuth2(secrets.web.client_id, secrets.web.client_secret, secrets.web.redirect_uris[0]);
|
|
29
|
-
const tokens = await (0, secrets_1.getCredentials)(profile, googleAuth, options);
|
|
30
|
-
googleAuth.setCredentials(tokens);
|
|
31
|
-
googleapis_1.google.options({ auth: googleAuth });
|
|
32
|
-
return googleAuth;
|
|
33
|
-
}
|
|
34
|
-
exports.getAuth = getAuth;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAuth = exports.login = void 0;
|
|
7
|
+
const googleapis_1 = require("googleapis");
|
|
8
|
+
const logger_1 = require("@anmiles/logger");
|
|
9
|
+
const profiles_1 = require("./profiles");
|
|
10
|
+
const secrets_1 = require("./secrets");
|
|
11
|
+
const auth_1 = __importDefault(require("./auth"));
|
|
12
|
+
exports.default = { login, getAuth };
|
|
13
|
+
async function login(profile, options) {
|
|
14
|
+
const profiles = (0, profiles_1.getProfiles)().filter((p) => !profile || p === profile);
|
|
15
|
+
for (const profile of profiles) {
|
|
16
|
+
if (!(options === null || options === void 0 ? void 0 : options.hideProgress)) {
|
|
17
|
+
(0, logger_1.warn)(`${profile} - logging in...`);
|
|
18
|
+
}
|
|
19
|
+
await auth_1.default.getAuth(profile, options);
|
|
20
|
+
if (!(options === null || options === void 0 ? void 0 : options.hideProgress)) {
|
|
21
|
+
(0, logger_1.info)(`${profile} - logged in successfully`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.login = login;
|
|
26
|
+
async function getAuth(profile, options) {
|
|
27
|
+
const secrets = (0, secrets_1.getSecrets)(profile);
|
|
28
|
+
const googleAuth = new googleapis_1.google.auth.OAuth2(secrets.web.client_id, secrets.web.client_secret, secrets.web.redirect_uris[0]);
|
|
29
|
+
const tokens = await (0, secrets_1.getCredentials)(profile, googleAuth, options);
|
|
30
|
+
googleAuth.setCredentials(tokens);
|
|
31
|
+
googleapis_1.google.options({ auth: googleAuth });
|
|
32
|
+
return googleAuth;
|
|
33
|
+
}
|
|
34
|
+
exports.getAuth = getAuth;
|
|
35
35
|
//# sourceMappingURL=auth.js.map
|
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;AAEpC,4CAA6C;AAE7C,yCAAyC;AACzC,uCAAuD;AAEvD,kDAA0B;AAG1B,kBAAe,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAElC,KAAK,UAAU,KAAK,CAAC,OAAgB,EAAE,OAAqC;IAC3E,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,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAA,EAAE;YAC3B,IAAA,aAAI,EAAC,GAAG,OAAO,kBAAkB,CAAC,CAAC;SACnC;QAED,MAAM,cAAI,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAErC,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAA,EAAE;YAC3B,IAAA,aAAI,EAAC,GAAG,OAAO,2BAA2B,CAAC,CAAC;SAC5C;KACD;AACF,CAAC;AAjBQ,sBAAK;AAmBd,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,mBAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAG,UAAU,EAAE,CAAC,CAAC;IACtC,OAAO,UAAU,CAAC;AACnB,CAAC;AAhCe,0BAAO"}
|
package/dist/lib/jsonLib.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export { getJSON, getJSONAsync, writeJSON, readJSON };
|
|
2
|
-
declare const _default: {
|
|
3
|
-
getJSON: typeof getJSON;
|
|
4
|
-
getJSONAsync: typeof getJSONAsync;
|
|
5
|
-
writeJSON: typeof writeJSON;
|
|
6
|
-
readJSON: typeof readJSON;
|
|
7
|
-
checkJSON: typeof checkJSON;
|
|
8
|
-
};
|
|
9
|
-
export default _default;
|
|
10
|
-
declare function getJSON<T>(filename: string, createCallback: () => Exclude<T, Promise<any>>, validateJSON?: (json: T) => boolean): T;
|
|
11
|
-
declare function getJSONAsync<T>(filename: string, createCallbackAsync: () => Promise<T>, validateJSONAsync?: (json: T) => Promise<boolean>): Promise<T>;
|
|
12
|
-
declare function writeJSON<T>(filename: string, json: T): void;
|
|
13
|
-
declare function readJSON<T>(filename: string): T;
|
|
14
|
-
declare function checkJSON<T>(filename: string, json: T): void;
|
|
1
|
+
export { getJSON, getJSONAsync, writeJSON, readJSON };
|
|
2
|
+
declare const _default: {
|
|
3
|
+
getJSON: typeof getJSON;
|
|
4
|
+
getJSONAsync: typeof getJSONAsync;
|
|
5
|
+
writeJSON: typeof writeJSON;
|
|
6
|
+
readJSON: typeof readJSON;
|
|
7
|
+
checkJSON: typeof checkJSON;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
10
|
+
declare function getJSON<T>(filename: string, createCallback: () => Exclude<T, Promise<any>>, validateJSON?: (json: T) => boolean): T;
|
|
11
|
+
declare function getJSONAsync<T>(filename: string, createCallbackAsync: () => Promise<T>, validateJSONAsync?: (json: T) => Promise<boolean>): Promise<T>;
|
|
12
|
+
declare function writeJSON<T>(filename: string, json: T): void;
|
|
13
|
+
declare function readJSON<T>(filename: string): T;
|
|
14
|
+
declare function checkJSON<T>(filename: string, json: T): void;
|
package/dist/lib/jsonLib.js
CHANGED
|
@@ -1,56 +1,55 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.readJSON = exports.writeJSON = exports.getJSONAsync = exports.getJSON = void 0;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readJSON = exports.writeJSON = exports.getJSONAsync = exports.getJSON = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const paths_1 = require("./paths");
|
|
9
|
+
const jsonLib_1 = __importDefault(require("./jsonLib"));
|
|
10
|
+
exports.default = { getJSON, getJSONAsync, writeJSON, readJSON, checkJSON };
|
|
11
|
+
function getJSON(filename, createCallback, validateJSON) {
|
|
12
|
+
if (fs_1.default.existsSync(filename)) {
|
|
13
|
+
const json = jsonLib_1.default.readJSON(filename);
|
|
14
|
+
if (!validateJSON || validateJSON(json)) {
|
|
15
|
+
return json;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const json = createCallback();
|
|
19
|
+
jsonLib_1.default.checkJSON(filename, json);
|
|
20
|
+
(0, paths_1.ensureFile)(filename);
|
|
21
|
+
jsonLib_1.default.writeJSON(filename, json);
|
|
22
|
+
return json;
|
|
23
|
+
}
|
|
24
|
+
exports.getJSON = getJSON;
|
|
25
|
+
async function getJSONAsync(filename, createCallbackAsync, validateJSONAsync) {
|
|
26
|
+
if (fs_1.default.existsSync(filename)) {
|
|
27
|
+
const json = jsonLib_1.default.readJSON(filename);
|
|
28
|
+
if (!validateJSONAsync || await validateJSONAsync(json)) {
|
|
29
|
+
return json;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const json = await createCallbackAsync();
|
|
33
|
+
jsonLib_1.default.checkJSON(filename, json);
|
|
34
|
+
(0, paths_1.ensureFile)(filename);
|
|
35
|
+
jsonLib_1.default.writeJSON(filename, json);
|
|
36
|
+
return json;
|
|
37
|
+
}
|
|
38
|
+
exports.getJSONAsync = getJSONAsync;
|
|
39
|
+
function writeJSON(filename, json) {
|
|
40
|
+
const jsonString = JSON.stringify(json, null, ' ');
|
|
41
|
+
fs_1.default.writeFileSync(filename, jsonString);
|
|
42
|
+
}
|
|
43
|
+
exports.writeJSON = writeJSON;
|
|
44
|
+
function readJSON(filename) {
|
|
45
|
+
const jsonString = fs_1.default.readFileSync(filename).toString();
|
|
46
|
+
return JSON.parse(jsonString);
|
|
47
|
+
}
|
|
48
|
+
exports.readJSON = readJSON;
|
|
49
|
+
function checkJSON(filename, json) {
|
|
50
|
+
if (json) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
throw `File ${filename} doesn't exist and should be created with initial data, but function createCallback returned nothing`;
|
|
54
|
+
}
|
|
56
55
|
//# sourceMappingURL=jsonLib.js.map
|
package/dist/lib/jsonLib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonLib.js","sourceRoot":"","sources":["../../src/lib/jsonLib.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,
|
|
1
|
+
{"version":3,"file":"jsonLib.js","sourceRoot":"","sources":["../../src/lib/jsonLib.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,mCAAqC;AAErC,wDAAgC;AAGhC,kBAAe,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAEzE,SAAS,OAAO,CAAI,QAAgB,EAAE,cAA8C,EAAE,YAAmC;IACxH,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC5B,MAAM,IAAI,GAAG,iBAAO,CAAC,QAAQ,CAAI,QAAQ,CAAC,CAAC;QAE3C,IAAI,CAAC,YAAY,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE;YACxC,OAAO,IAAI,CAAC;SACZ;KACD;IAED,MAAM,IAAI,GAAG,cAAc,EAAE,CAAC;IAC9B,iBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClC,IAAA,kBAAU,EAAC,QAAQ,CAAC,CAAC;IACrB,iBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AACb,CAAC;AAjBQ,0BAAO;AAmBhB,KAAK,UAAU,YAAY,CAAI,QAAgB,EAAE,mBAAqC,EAAE,iBAAiD;IACxI,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC5B,MAAM,IAAI,GAAG,iBAAO,CAAC,QAAQ,CAAI,QAAQ,CAAC,CAAC;QAE3C,IAAI,CAAC,iBAAiB,IAAI,MAAM,iBAAiB,CAAC,IAAI,CAAC,EAAE;YACxD,OAAO,IAAI,CAAC;SACZ;KACD;IAED,MAAM,IAAI,GAAG,MAAM,mBAAmB,EAAE,CAAC;IACzC,iBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClC,IAAA,kBAAU,EAAC,QAAQ,CAAC,CAAC;IACrB,iBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AACb,CAAC;AAjCiB,oCAAY;AAmC9B,SAAS,SAAS,CAAI,QAAgB,EAAE,IAAO;IAC9C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACtD,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AACxC,CAAC;AAtC+B,8BAAS;AAwCzC,SAAS,QAAQ,CAAI,QAAgB;IACpC,MAAM,UAAU,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;IACxD,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,CAAM,CAAC;AACpC,CAAC;AA3C0C,4BAAQ;AA6CnD,SAAS,SAAS,CAAI,QAAgB,EAAE,IAAO;IAC9C,IAAI,IAAI,EAAE;QACT,OAAO;KACP;IAED,MAAM,QAAQ,QAAQ,sGAAsG,CAAC;AAC9H,CAAC"}
|