@anmiles/google-api-wrapper 17.0.8 → 18.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/.eslintignore +2 -0
- package/.eslintrc.js +23 -7
- package/.vscode/settings.json +1 -0
- package/CHANGELOG.md +10 -0
- package/README.md +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/api.d.ts +16 -16
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/api.js +9 -7
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/auth.d.ts +3 -3
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +1 -1
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/paths.d.ts +5 -5
- package/dist/lib/paths.d.ts.map +1 -1
- package/dist/lib/paths.js +1 -1
- package/dist/lib/paths.js.map +1 -1
- package/dist/lib/profiles.d.ts +4 -4
- package/dist/lib/profiles.d.ts.map +1 -1
- package/dist/lib/profiles.js +4 -4
- package/dist/lib/profiles.js.map +1 -1
- package/dist/lib/renderer.d.ts +2 -2
- package/dist/lib/renderer.d.ts.map +1 -1
- package/dist/lib/renderer.js +1 -1
- package/dist/lib/renderer.js.map +1 -1
- package/dist/lib/secrets.d.ts +14 -13
- package/dist/lib/secrets.d.ts.map +1 -1
- package/dist/lib/secrets.js +13 -12
- package/dist/lib/secrets.js.map +1 -1
- package/dist/types/options.d.ts +9 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/{common.js → options.js} +1 -1
- package/dist/types/options.js.map +1 -0
- package/dist/types/secrets.d.ts +2 -5
- package/dist/types/secrets.d.ts.map +1 -1
- package/jest.config.js +3 -11
- package/package.json +63 -55
- package/src/index.ts +2 -0
- package/src/lib/__tests__/api.test.ts +30 -24
- package/src/lib/__tests__/auth.test.ts +4 -5
- package/src/lib/__tests__/paths.test.ts +6 -5
- package/src/lib/__tests__/profiles.test.ts +17 -27
- package/src/lib/__tests__/renderer.test.ts +7 -7
- package/src/lib/__tests__/secrets.test.ts +54 -77
- package/src/lib/api.ts +36 -26
- package/src/lib/auth.ts +5 -5
- package/src/lib/paths.ts +8 -8
- package/src/lib/profiles.ts +6 -6
- package/src/lib/renderer.ts +8 -9
- package/src/lib/secrets.ts +22 -19
- package/src/types/options.ts +10 -0
- package/src/types/secrets.ts +9 -13
- package/tsconfig.build.json +2 -2
- package/tsconfig.json +5 -5
- package/tsconfig.test.json +3 -3
- package/.gitlab-ci.yml +0 -117
- package/dist/types/common.d.ts +0 -4
- package/dist/types/common.d.ts.map +0 -1
- package/dist/types/common.js.map +0 -1
- package/dist/types/index.d.ts +0 -3
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -19
- package/dist/types/index.js.map +0 -1
- package/src/types/common.ts +0 -3
- package/src/types/index.ts +0 -2
package/.eslintignore
ADDED
package/.eslintrc.js
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
root
|
|
2
|
+
root : true,
|
|
3
|
+
|
|
3
4
|
extends : [
|
|
4
|
-
'./node_modules/@anmiles/eslint-config
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'**/node_modules/',
|
|
8
|
-
'coverage/',
|
|
9
|
-
'dist/',
|
|
5
|
+
'./node_modules/@anmiles/eslint-config/src/base.preset.js',
|
|
6
|
+
'./node_modules/@anmiles/eslint-config/src/ts.preset.js',
|
|
7
|
+
'./node_modules/@anmiles/eslint-config/src/jest.preset.js',
|
|
10
8
|
],
|
|
9
|
+
|
|
11
10
|
globals : {
|
|
12
11
|
NodeJS : true,
|
|
13
12
|
},
|
|
13
|
+
|
|
14
|
+
rules : {
|
|
15
|
+
camelcase : [ 'error', { allow : [
|
|
16
|
+
'access_token',
|
|
17
|
+
'access_type',
|
|
18
|
+
'auth_provider_x509_cert_url',
|
|
19
|
+
'auth_uri',
|
|
20
|
+
'calendar_v3',
|
|
21
|
+
'client_id',
|
|
22
|
+
'client_secret',
|
|
23
|
+
'expiry_date',
|
|
24
|
+
'project_id',
|
|
25
|
+
'redirect_uris',
|
|
26
|
+
'refresh_token',
|
|
27
|
+
'token_uri',
|
|
28
|
+
] } ],
|
|
29
|
+
},
|
|
14
30
|
};
|
package/.vscode/settings.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +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
|
+
## [18.0.0](../../tags/v18.0.0) - 2024-03-16
|
|
9
|
+
### Changed
|
|
10
|
+
- Update eslint config and raise minimum supported NodeJS version to match one in typescript-eslint plugin
|
|
11
|
+
- Update .npmignore
|
|
12
|
+
- Unify jest.config.js by removing redundant patterns and providing support for both ts and tsx
|
|
13
|
+
|
|
14
|
+
## [17.0.9](../../tags/v17.0.9) - 2024-01-31
|
|
15
|
+
### Changed
|
|
16
|
+
- Migrate to GitHub
|
|
17
|
+
|
|
8
18
|
## [17.0.8](../../tags/v17.0.8) - 2024-01-29
|
|
9
19
|
### Changed
|
|
10
20
|
- Explicitly specify ignores from .gitignore in .eslintrc.js
|
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# @anmiles/google-api-wrapper
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Wrapper around googleapis for getting data shortly
|
|
4
|
+
- provides quick interface for getting google API data
|
|
5
|
+
- incapsulates auth process
|
|
6
|
+
- combines getting paged items in one call
|
|
5
7
|
----
|
|
6
8
|
|
|
7
9
|
## Installation
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* istanbul ignore file */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.getAuth = exports.login = exports.filterProfiles = exports.getProfiles = exports.createProfile = exports.getAPI = void 0;
|
|
4
5
|
var api_1 = require("./lib/api");
|
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,0BAA0B;;;AAE1B,iCAAmC;AAA1B,6FAAA,MAAM,OAAA;AACf,2CAA4E;AAAnE,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AAAE,0GAAA,cAAc,OAAA;AACnD,mCAA4C;AAAnC,6FAAA,KAAK,OAAA;AAAE,+FAAA,OAAO,OAAA"}
|
package/dist/lib/api.d.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { AuthOptions, CommonOptions } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
pageToken: string | undefined;
|
|
7
|
-
}, options?: GoogleApis.Common.MethodOptions): Promise<GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>>>;
|
|
8
|
-
(callback: (err: Error | null, res?: GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>> | null) => void): void;
|
|
9
|
-
};
|
|
2
|
+
import type { AuthOptions, CommonOptions } from '../types/options';
|
|
3
|
+
import '@anmiles/prototypes';
|
|
4
|
+
type ListParams = Record<string, unknown> & {
|
|
5
|
+
pageToken: string | undefined;
|
|
10
6
|
};
|
|
11
|
-
|
|
7
|
+
interface CommonAPI<TItem> {
|
|
8
|
+
list: (params?: ListParams, options?: GoogleApis.Common.MethodOptions) => Promise<GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>>>;
|
|
9
|
+
}
|
|
10
|
+
interface CommonResponse<TItem> {
|
|
12
11
|
items?: TItem[];
|
|
13
12
|
pageInfo?: {
|
|
14
13
|
totalResults?: number | null | undefined;
|
|
15
14
|
};
|
|
16
15
|
nextPageToken?: string | null | undefined;
|
|
17
|
-
}
|
|
16
|
+
}
|
|
18
17
|
declare class API<TGoogleAPI> {
|
|
19
|
-
private getter;
|
|
20
|
-
private profile;
|
|
21
|
-
private authOptions?;
|
|
22
|
-
private auth;
|
|
18
|
+
private readonly getter;
|
|
19
|
+
private readonly profile;
|
|
20
|
+
private readonly authOptions?;
|
|
23
21
|
api: TGoogleAPI | undefined;
|
|
22
|
+
private auth;
|
|
24
23
|
constructor(getter: (auth: GoogleApis.Common.OAuth2Client) => TGoogleAPI, profile: string, authOptions?: AuthOptions | undefined);
|
|
25
24
|
init(): Promise<void>;
|
|
26
|
-
getItems<TItem>(selectAPI: (api: TGoogleAPI) => CommonAPI<TItem>, params:
|
|
25
|
+
getItems<TItem>(selectAPI: (api: TGoogleAPI) => CommonAPI<TItem>, params: object, options?: CommonOptions): Promise<TItem[]>;
|
|
27
26
|
}
|
|
28
27
|
declare function getAPI<TGoogleAPI>(getter: (auth: GoogleApis.Common.OAuth2Client) => TGoogleAPI, profile: string, authOptions?: AuthOptions): Promise<API<TGoogleAPI>>;
|
|
29
|
-
export { getAPI };
|
|
28
|
+
export { getAPI, API };
|
|
29
|
+
export type { CommonResponse };
|
|
30
30
|
declare const _default: {
|
|
31
31
|
getAPI: typeof getAPI;
|
|
32
32
|
API: typeof API;
|
package/dist/lib/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAGzC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAGzC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAGnE,OAAO,qBAAqB,CAAC;AAI7B,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC3C,SAAS,EAAG,MAAM,GAAG,SAAS,CAAC;CAC/B,CAAC;AAEF,UAAU,SAAS,CAAC,KAAK;IACxB,IAAI,EAAG,CACN,MAAM,CAAC,EAAE,UAAU,EACnB,OAAO,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,aAAa,KACrC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CACtE;AAED,UAAU,cAAc,CAAC,KAAK;IAC7B,KAAK,CAAC,EAAM,KAAK,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE;QACV,YAAY,CAAC,EAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;KAC1C,CAAC;IACF,aAAa,CAAC,EAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;CAC3C;AAED,cAAM,GAAG,CAAC,UAAU;IAKlB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAN9B,GAAG,EAAY,UAAU,GAAG,SAAS,CAAC;IACtC,OAAO,CAAC,IAAI,CAA8C;gBAGxC,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,KAAK,UAAU,EAC5D,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,yBAAa;IAGrC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,UAAU,KAAK,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;CAyClI;AAED,iBAAe,MAAM,CAAC,UAAU,EAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,KAAK,UAAU,EAC5D,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAY1B;AAED,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;AACvB,YAAY,EAAE,cAAc,EAAE,CAAC;;;;;AAC/B,wBAA+B"}
|
package/dist/lib/api.js
CHANGED
|
@@ -3,18 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAPI = void 0;
|
|
6
|
+
exports.API = exports.getAPI = void 0;
|
|
7
7
|
const logger_1 = require("@anmiles/logger");
|
|
8
8
|
const sleep_1 = __importDefault(require("@anmiles/sleep"));
|
|
9
9
|
const auth_1 = require("./auth");
|
|
10
10
|
const secrets_1 = require("./secrets");
|
|
11
|
+
require("@anmiles/prototypes");
|
|
11
12
|
const requestInterval = 300;
|
|
12
13
|
class API {
|
|
13
14
|
getter;
|
|
14
15
|
profile;
|
|
15
16
|
authOptions;
|
|
16
|
-
auth;
|
|
17
17
|
api;
|
|
18
|
+
auth;
|
|
18
19
|
constructor(getter, profile, authOptions) {
|
|
19
20
|
this.getter = getter;
|
|
20
21
|
this.profile = profile;
|
|
@@ -31,13 +32,13 @@ class API {
|
|
|
31
32
|
let response;
|
|
32
33
|
try {
|
|
33
34
|
if (!this.api) {
|
|
34
|
-
throw 'API is not initialized. Call `init` before getting items.';
|
|
35
|
+
throw new Error('API is not initialized. Call `init` before getting items.');
|
|
35
36
|
}
|
|
36
37
|
const selectedAPI = selectAPI(this.api);
|
|
37
38
|
response = await selectedAPI.list({ ...params, pageToken });
|
|
38
39
|
}
|
|
39
40
|
catch (ex) {
|
|
40
|
-
const message =
|
|
41
|
+
const { message } = Error.parse(ex);
|
|
41
42
|
if ((message === 'invalid_grant' || message === 'Invalid credentials') && !this.authOptions?.temporary) {
|
|
42
43
|
(0, logger_1.warn)('Access token stored is invalid, re-creating...');
|
|
43
44
|
(0, secrets_1.deleteCredentials)(this.profile);
|
|
@@ -50,7 +51,7 @@ class API {
|
|
|
50
51
|
}
|
|
51
52
|
response.data.items?.forEach((item) => items.push(item));
|
|
52
53
|
if (!options?.hideProgress) {
|
|
53
|
-
(0, logger_1.log)(`Getting items (${items.length} of ${response.data.pageInfo?.totalResults
|
|
54
|
+
(0, logger_1.log)(`Getting items (${items.length} of ${response.data.pageInfo?.totalResults ?? 'many'})...`);
|
|
54
55
|
}
|
|
55
56
|
await (0, sleep_1.default)(requestInterval);
|
|
56
57
|
pageToken = response.data.nextPageToken;
|
|
@@ -58,11 +59,12 @@ class API {
|
|
|
58
59
|
return items;
|
|
59
60
|
}
|
|
60
61
|
}
|
|
62
|
+
exports.API = API;
|
|
61
63
|
async function getAPI(getter, profile, authOptions) {
|
|
62
64
|
if (!authOptions?.temporary) {
|
|
63
|
-
const writableScopes = authOptions?.scopes?.filter((scope) => !scope.endsWith('.readonly'))
|
|
65
|
+
const writableScopes = authOptions?.scopes?.filter((scope) => !scope.endsWith('.readonly')) ?? [];
|
|
64
66
|
if (writableScopes.length > 0) {
|
|
65
|
-
(0, logger_1.warn)(`WARNING: trying to create permanent credentials using non-readonly scopes (${writableScopes}). Permanent credentials will be stored in the file and potentially might be re-used to modify your data`);
|
|
67
|
+
(0, logger_1.warn)(`WARNING: trying to create permanent credentials using non-readonly scopes (${writableScopes.join(', ')}). Permanent credentials will be stored in the file and potentially might be re-used to modify your data`);
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
const instance = new API(getter, profile, authOptions);
|
package/dist/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":";;;;;;AACA,4CAA4C;AAC5C,2DAAmC;AAEnC,iCAAiC;AACjC,uCAA8C;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":";;;;;;AACA,4CAA4C;AAC5C,2DAAmC;AAEnC,iCAAiC;AACjC,uCAA8C;AAC9C,+BAA6B;AAE7B,MAAM,eAAe,GAAG,GAAG,CAAC;AAqB5B,MAAM,GAAG;IAKU;IACA;IACA;IANlB,GAAG,CAAmC;IAC9B,IAAI,CAA8C;IAE1D,YACkB,MAA4D,EAC5D,OAAe,EACf,WAAyB;QAFzB,WAAM,GAAN,MAAM,CAAsD;QAC5D,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAc;IACvC,CAAC;IAEL,KAAK,CAAC,IAAI;QACT,IAAI,CAAC,IAAI,GAAG,MAAM,IAAA,cAAO,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1D,IAAI,CAAC,GAAG,GAAI,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,QAAQ,CAAQ,SAAgD,EAAE,MAAc,EAAE,OAAuB;QAC9G,MAAM,KAAK,GAAY,EAAE,CAAC;QAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;QAErD,GAAG,CAAC;YACH,IAAI,QAAiE,CAAC;YAEtE,IAAI,CAAC;gBACJ,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;oBACf,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;gBAC9E,CAAC;gBAED,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBAExC,QAAQ,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;YAC7D,CAAC;YAAC,OAAO,EAAE,EAAE,CAAC;gBACb,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBAEpC,IAAI,CAAC,OAAO,KAAK,eAAe,IAAI,OAAO,KAAK,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC;oBACxG,IAAA,aAAI,EAAC,gDAAgD,CAAC,CAAC;oBACvD,IAAA,2BAAiB,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;oBAChC,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;oBAClB,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;gBAClD,CAAC;qBAAM,CAAC;oBACP,MAAM,EAAE,CAAC;gBACV,CAAC;YACF,CAAC;YAED,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAEzD,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;gBAC5B,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,IAAI,MAAM,MAAM,CAAC,CAAC;YAChG,CAAC;YAED,MAAM,IAAA,eAAK,EAAC,eAAe,CAAC,CAAC;YAC7B,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;QACzC,CAAC,QAAQ,SAAS,EAAE;QAEpB,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAoBgB,kBAAG;AAlBpB,KAAK,UAAU,MAAM,CACpB,MAA4D,EAC5D,OAAe,EACf,WAAyB;IAEzB,IAAI,CAAC,WAAW,EAAE,SAAS,EAAE,CAAC;QAC7B,MAAM,cAAc,GAAG,WAAW,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,CAAC;QAElG,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,IAAA,aAAI,EAAC,8EAA8E,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,0GAA0G,CAAC,CAAC;QACzN,CAAC;IACF,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAa,MAAM,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IACnE,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACtB,OAAO,QAAQ,CAAC;AACjB,CAAC;AAEQ,wBAAM;AAEf,kBAAe,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC"}
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { CommonOptions, AuthOptions } from '../types';
|
|
2
|
+
import type { CommonOptions, AuthOptions } from '../types/options';
|
|
3
|
+
declare function login(profile?: string, options?: AuthOptions & CommonOptions): Promise<void>;
|
|
4
|
+
declare function getAuth(profile: string, options?: AuthOptions): Promise<GoogleApis.Common.OAuth2Client>;
|
|
3
5
|
export { login, getAuth };
|
|
4
6
|
declare const _default: {
|
|
5
7
|
login: typeof login;
|
|
6
8
|
getAuth: typeof getAuth;
|
|
7
9
|
};
|
|
8
10
|
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>;
|
|
11
11
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/lib/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAMnE,iBAAe,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAc3F;AAED,iBAAe,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAatG;AAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;;;;;AAC1B,wBAAkC"}
|
package/dist/lib/auth.js
CHANGED
|
@@ -9,7 +9,6 @@ const logger_1 = require("@anmiles/logger");
|
|
|
9
9
|
const profiles_1 = require("./profiles");
|
|
10
10
|
const secrets_1 = require("./secrets");
|
|
11
11
|
const auth_1 = __importDefault(require("./auth"));
|
|
12
|
-
exports.default = { login, getAuth };
|
|
13
12
|
async function login(profile, options) {
|
|
14
13
|
const profiles = (0, profiles_1.getProfiles)().filter((p) => !profile || p === profile);
|
|
15
14
|
for (const profile of profiles) {
|
|
@@ -32,4 +31,5 @@ async function getAuth(profile, options) {
|
|
|
32
31
|
return googleAuth;
|
|
33
32
|
}
|
|
34
33
|
exports.getAuth = getAuth;
|
|
34
|
+
exports.default = { login, 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;AAEpC,4CAA6C;AAE7C,yCAAyC;AACzC,uCAAuD;AAEvD,kDAA0B;
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,4CAA6C;AAE7C,yCAAyC;AACzC,uCAAuD;AAEvD,kDAA0B;AAE1B,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,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;YAC5B,IAAA,aAAI,EAAC,GAAG,OAAO,kBAAkB,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,cAAI,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAErC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;YAC5B,IAAA,aAAI,EAAC,GAAG,OAAO,2BAA2B,CAAC,CAAC;QAC7C,CAAC;IACF,CAAC;AACF,CAAC;AAiBQ,sBAAK;AAfd,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;AAEe,0BAAO;AACvB,kBAAe,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/lib/paths.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { templates } from './renderer';
|
|
2
|
+
declare function getProfilesFile(): string;
|
|
3
|
+
declare function getScopesFile(): string;
|
|
4
|
+
declare function getSecretsFile(profile: string): string;
|
|
5
|
+
declare function getCredentialsFile(profile: string): string;
|
|
6
|
+
declare function getTemplateFile(templateName: keyof typeof templates): string;
|
|
2
7
|
export { getProfilesFile, getScopesFile, getSecretsFile, getCredentialsFile, getTemplateFile };
|
|
3
8
|
declare const _default: {
|
|
4
9
|
getProfilesFile: typeof getProfilesFile;
|
|
@@ -8,9 +13,4 @@ declare const _default: {
|
|
|
8
13
|
getTemplateFile: typeof getTemplateFile;
|
|
9
14
|
};
|
|
10
15
|
export default _default;
|
|
11
|
-
declare function getProfilesFile(): string;
|
|
12
|
-
declare function getScopesFile(): string;
|
|
13
|
-
declare function getSecretsFile(profile: string): string;
|
|
14
|
-
declare function getCredentialsFile(profile: string): string;
|
|
15
|
-
declare function getTemplateFile(templateName: keyof typeof templates): string;
|
|
16
16
|
//# sourceMappingURL=paths.d.ts.map
|
package/dist/lib/paths.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAS5C,iBAAS,eAAe,IAAI,MAAM,CAEjC;AAED,iBAAS,aAAa,IAAI,MAAM,CAE/B;AAED,iBAAS,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,iBAAS,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,iBAAS,eAAe,CAAC,YAAY,EAAE,MAAM,OAAO,SAAS,GAAG,MAAM,CAErE;AAED,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,EAAE,CAAC;;;;;;;;AAC/F,wBAAuG"}
|
package/dist/lib/paths.js
CHANGED
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getTemplateFile = exports.getCredentialsFile = exports.getSecretsFile = exports.getScopesFile = exports.getProfilesFile = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
|
-
exports.default = { getProfilesFile, getScopesFile, getSecretsFile, getCredentialsFile, getTemplateFile };
|
|
9
8
|
const dirPaths = {
|
|
10
9
|
input: 'input',
|
|
11
10
|
secrets: 'secrets',
|
|
@@ -32,4 +31,5 @@ function getTemplateFile(templateName) {
|
|
|
32
31
|
return path_1.default.join(dirPaths.templates, `${templateName}.html`);
|
|
33
32
|
}
|
|
34
33
|
exports.getTemplateFile = getTemplateFile;
|
|
34
|
+
exports.default = { getProfilesFile, getScopesFile, getSecretsFile, getCredentialsFile, getTemplateFile };
|
|
35
35
|
//# sourceMappingURL=paths.js.map
|
package/dist/lib/paths.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAGxB,MAAM,QAAQ,GAAG;IAChB,KAAK,EAAO,OAAO;IACnB,OAAO,EAAK,SAAS;IACrB,+CAA+C;IAC/C,SAAS,EAAG,yDAAyD;CACrE,CAAC;AAEF,SAAS,eAAe;IACvB,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AACnD,CAAC;AAkBQ,0CAAe;AAhBxB,SAAS,aAAa;IACrB,OAAO,aAAa,CAAC;AACtB,CAAC;AAcyB,sCAAa;AAZvC,SAAS,cAAc,CAAC,OAAe;IACtC,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,OAAO,CAAC,CAAC;AACvD,CAAC;AAUwC,wCAAc;AARvD,SAAS,kBAAkB,CAAC,OAAe;IAC1C,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,mBAAmB,CAAC,CAAC;AACnE,CAAC;AAMwD,gDAAkB;AAJ3E,SAAS,eAAe,CAAC,YAAoC;IAC5D,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,YAAY,OAAO,CAAC,CAAC;AAC9D,CAAC;AAE4E,0CAAe;AAC5F,kBAAe,EAAE,eAAe,EAAE,aAAa,EAAE,cAAc,EAAE,kBAAkB,EAAE,eAAe,EAAE,CAAC"}
|
package/dist/lib/profiles.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import '@anmiles/prototypes';
|
|
2
|
+
declare function getProfiles(): string[];
|
|
3
|
+
declare function setProfiles(profiles: string[]): void;
|
|
4
|
+
declare function createProfile(profile?: string): void;
|
|
5
|
+
declare function filterProfiles(profile?: string): string[];
|
|
2
6
|
export { getProfiles, setProfiles, createProfile, filterProfiles };
|
|
3
7
|
declare const _default: {
|
|
4
8
|
getProfiles: typeof getProfiles;
|
|
@@ -7,8 +11,4 @@ declare const _default: {
|
|
|
7
11
|
filterProfiles: typeof filterProfiles;
|
|
8
12
|
};
|
|
9
13
|
export default _default;
|
|
10
|
-
declare function getProfiles(): string[];
|
|
11
|
-
declare function setProfiles(profiles: string[]): void;
|
|
12
|
-
declare function createProfile(profile?: string): void;
|
|
13
|
-
declare function filterProfiles(profile?: string): string[];
|
|
14
14
|
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":"AACA,OAAO,qBAAqB,CAAC;AAK7B,
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":"AACA,OAAO,qBAAqB,CAAC;AAK7B,iBAAS,WAAW,IAAI,MAAM,EAAE,CAG/B;AAED,iBAAS,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAG7C;AAED,iBAAS,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAa7C;AAED,iBAAS,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAgBlD;AAED,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC;;;;;;;AACnE,wBAA2E"}
|
package/dist/lib/profiles.js
CHANGED
|
@@ -8,7 +8,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
require("@anmiles/prototypes");
|
|
9
9
|
const paths_1 = require("./paths");
|
|
10
10
|
const profiles_1 = __importDefault(require("./profiles"));
|
|
11
|
-
exports.default = { getProfiles, setProfiles, createProfile, filterProfiles };
|
|
12
11
|
function getProfiles() {
|
|
13
12
|
const profilesFile = (0, paths_1.getProfilesFile)();
|
|
14
13
|
return fs_1.default.getJSON(profilesFile, () => []);
|
|
@@ -21,7 +20,7 @@ function setProfiles(profiles) {
|
|
|
21
20
|
exports.setProfiles = setProfiles;
|
|
22
21
|
function createProfile(profile) {
|
|
23
22
|
if (!profile) {
|
|
24
|
-
throw 'Usage: `npm run create <profile>` where `profile` - is any profile name you want';
|
|
23
|
+
throw new Error('Usage: `npm run create <profile>` where `profile` - is any profile name you want');
|
|
25
24
|
}
|
|
26
25
|
const existingProfiles = profiles_1.default.getProfiles();
|
|
27
26
|
if (existingProfiles.includes(profile)) {
|
|
@@ -34,7 +33,7 @@ exports.createProfile = createProfile;
|
|
|
34
33
|
function filterProfiles(profile) {
|
|
35
34
|
const existingProfiles = profiles_1.default.getProfiles();
|
|
36
35
|
if (existingProfiles.length === 0) {
|
|
37
|
-
throw 'Please `npm run create` at least one profile';
|
|
36
|
+
throw new Error('Please `npm run create` at least one profile');
|
|
38
37
|
}
|
|
39
38
|
if (!profile) {
|
|
40
39
|
return existingProfiles;
|
|
@@ -42,7 +41,8 @@ function filterProfiles(profile) {
|
|
|
42
41
|
if (existingProfiles.includes(profile)) {
|
|
43
42
|
return [profile];
|
|
44
43
|
}
|
|
45
|
-
throw `Profile '${profile}' does not exist
|
|
44
|
+
throw new Error(`Profile '${profile}' does not exist`);
|
|
46
45
|
}
|
|
47
46
|
exports.filterProfiles = filterProfiles;
|
|
47
|
+
exports.default = { getProfiles, setProfiles, createProfile, filterProfiles };
|
|
48
48
|
//# sourceMappingURL=profiles.js.map
|
package/dist/lib/profiles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAA6B;AAC7B,mCAA0C;AAE1C,0DAAkC;
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAA6B;AAC7B,mCAA0C;AAE1C,0DAAkC;AAElC,SAAS,WAAW;IACnB,MAAM,YAAY,GAAG,IAAA,uBAAe,GAAE,CAAC;IACvC,OAAO,YAAE,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AAC3C,CAAC;AAwCQ,kCAAW;AAtCpB,SAAS,WAAW,CAAC,QAAkB;IACtC,MAAM,YAAY,GAAG,IAAA,uBAAe,GAAE,CAAC;IACvC,YAAE,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAmCqB,kCAAW;AAjCjC,SAAS,aAAa,CAAC,OAAgB;IACtC,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,kFAAkF,CAAC,CAAC;IACrG,CAAC;IAED,MAAM,gBAAgB,GAAG,kBAAQ,CAAC,WAAW,EAAE,CAAC;IAEhD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,OAAO;IACR,CAAC;IAED,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,kBAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AACxC,CAAC;AAoBkC,sCAAa;AAlBhD,SAAS,cAAc,CAAC,OAAgB;IACvC,MAAM,gBAAgB,GAAG,kBAAQ,CAAC,WAAW,EAAE,CAAC;IAEhD,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,CAAC,OAAO,EAAE,CAAC;QACd,OAAO,gBAAgB,CAAC;IACzB,CAAC;IAED,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACxC,OAAO,CAAE,OAAO,CAAE,CAAC;IACpB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,YAAY,OAAO,kBAAkB,CAAC,CAAC;AACxD,CAAC;AAEiD,wCAAc;AAChE,kBAAe,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC"}
|
package/dist/lib/renderer.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { templates, renderAuth, renderDone };
|
|
2
1
|
declare const templates: {
|
|
3
2
|
readonly page: readonly ["css", "content"];
|
|
4
3
|
readonly css: readonly [];
|
|
@@ -15,8 +14,9 @@ declare function renderAuth({ profile, authUrl, scope }: {
|
|
|
15
14
|
declare function renderDone({ profile }: {
|
|
16
15
|
profile: string;
|
|
17
16
|
}): string;
|
|
18
|
-
declare function render<T extends TemplateName>(templateName: T, values: Record<typeof templates[T][number], string>): string;
|
|
17
|
+
declare function render<T extends TemplateName>(templateName: T, values: Record<typeof templates[T][number], string | undefined>): string;
|
|
19
18
|
declare function getTemplate(templateName: TemplateName): string;
|
|
19
|
+
export { templates, renderAuth, renderDone };
|
|
20
20
|
declare const _default: {
|
|
21
21
|
templates: {
|
|
22
22
|
readonly page: readonly ["css", "content"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/lib/renderer.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/lib/renderer.ts"],"names":[],"mappings":"AAIA,QAAA,MAAM,SAAS;;;;;;CAML,CAAC;AAEX,KAAK,YAAY,GAAG,MAAM,OAAO,SAAS,CAAC;AAI3C,iBAAS,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE;IAAE,OAAO,EAAG,MAAM,CAAC;IAAC,OAAO,EAAG,MAAM,CAAC;IAAC,KAAK,EAAG,MAAM,EAAE,CAAA;CAAE,GAAG,MAAM,CAUjH;AAED,iBAAS,UAAU,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAG,MAAM,CAAA;CAAE,GAAG,MAAM,CAI7D;AAGD,iBAAS,MAAM,CAAC,CAAC,SAAS,YAAY,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,CAUhI;AAED,iBAAS,WAAW,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,CAQvD;AAED,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC;;;;;;;;;;;;;;AAC7C,wBAA0E"}
|
package/dist/lib/renderer.js
CHANGED
|
@@ -38,7 +38,7 @@ function render(templateName, values) {
|
|
|
38
38
|
let html = renderer_1.default.getTemplate(templateName);
|
|
39
39
|
const allValues = values;
|
|
40
40
|
for (const variable of templates[templateName]) {
|
|
41
|
-
const value = allValues[variable]
|
|
41
|
+
const value = allValues[variable] ?? '';
|
|
42
42
|
html = html.replace(`\${${variable}}`, value);
|
|
43
43
|
}
|
|
44
44
|
return html;
|
package/dist/lib/renderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/lib/renderer.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,0DAAkC;AAClC,mCAA0C;
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/lib/renderer.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,0DAAkC;AAClC,mCAA0C;AAE1C,MAAM,SAAS,GAAG;IACjB,IAAI,EAAI,CAAE,KAAK,EAAE,SAAS,CAAW;IACrC,GAAG,EAAK,EAAY;IACpB,IAAI,EAAI,CAAE,SAAS,EAAE,SAAS,EAAE,YAAY,CAAE;IAC9C,KAAK,EAAG,CAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAW;IAC5C,IAAI,EAAI,CAAE,SAAS,CAAW;CACrB,CAAC;AA+CF,8BAAS;AA3ClB,MAAM,OAAO,GAAG,EAAkC,CAAC;AAEnD,SAAS,UAAU,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAA4D;IACxG,MAAM,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE;QACnD,IAAI,EAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAG;QAC3B,KAAK,EAAG,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,8CAA8C,CAAC,CAAC,CAAC,2CAA2C;QAC9H,IAAI,EAAI,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE;KACjD,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEf,MAAM,GAAG,GAAO,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AACzC,CAAC;AA+BmB,gCAAU;AA7B9B,SAAS,UAAU,CAAC,EAAE,OAAO,EAAwB;IACpD,MAAM,GAAG,GAAO,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AACzC,CAAC;AAyB+B,gCAAU;AAvB1C,kBAAkB;AAClB,SAAS,MAAM,CAAyB,YAAe,EAAE,MAA+D;IACvH,IAAI,IAAI,GAAU,kBAAQ,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,MAA4E,CAAC;IAE/F,KAAK,MAAM,QAAQ,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;QAChD,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,GAAU,IAAI,CAAC,OAAO,CAAC,MAAM,QAAQ,GAAG,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,WAAW,CAAC,YAA0B;IAC9C,IAAI,CAAC,CAAC,YAAY,IAAI,OAAO,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,GAAc,IAAA,uBAAe,EAAC,YAAY,CAAC,CAAC;QACtD,MAAM,QAAQ,GAAU,YAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;QACzD,OAAO,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAC;IAClC,CAAC;IAED,OAAO,OAAO,CAAC,YAAY,CAAC,CAAC;AAC9B,CAAC;AAGD,kBAAe,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,CAAC"}
|
package/dist/lib/secrets.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type { Secrets
|
|
2
|
+
import type { Secrets } from '../types/secrets';
|
|
3
|
+
import type { AuthOptions } from '../types/options';
|
|
3
4
|
import '@anmiles/prototypes';
|
|
5
|
+
declare function getScopes(): string[];
|
|
6
|
+
declare function getSecrets(profile: string): Secrets;
|
|
7
|
+
declare function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials>;
|
|
8
|
+
declare function validateCredentials(credentials: GoogleApis.Auth.Credentials): Promise<{
|
|
9
|
+
isValid: boolean;
|
|
10
|
+
validationError?: string;
|
|
11
|
+
}>;
|
|
12
|
+
declare function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client, options?: AuthOptions, prompt?: GoogleApis.Auth.GenerateAuthUrlOpts['prompt']): Promise<GoogleApis.Auth.Credentials>;
|
|
13
|
+
declare function deleteCredentials(profile: string): void;
|
|
14
|
+
declare function checkSecrets(profile: string, secretsObject: Secrets, secretsFile: string): true;
|
|
15
|
+
declare function getScopesError(scopesFile: string): string;
|
|
16
|
+
declare function getSecretsError(profile: string, secretsFile: string): string;
|
|
4
17
|
export { getSecrets, getCredentials, deleteCredentials };
|
|
5
18
|
declare const _default: {
|
|
6
19
|
getScopes: typeof getScopes;
|
|
@@ -14,16 +27,4 @@ declare const _default: {
|
|
|
14
27
|
getScopesError: typeof getScopesError;
|
|
15
28
|
};
|
|
16
29
|
export default _default;
|
|
17
|
-
declare function getScopes(): string[];
|
|
18
|
-
declare function getSecrets(profile: string): Secrets;
|
|
19
|
-
declare function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials>;
|
|
20
|
-
declare function validateCredentials(credentials: GoogleApis.Auth.Credentials): Promise<{
|
|
21
|
-
isValid: boolean;
|
|
22
|
-
validationError?: string;
|
|
23
|
-
}>;
|
|
24
|
-
declare function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client, options?: AuthOptions, prompt?: GoogleApis.Auth.GenerateAuthUrlOpts['prompt']): Promise<GoogleApis.Auth.Credentials>;
|
|
25
|
-
declare function deleteCredentials(profile: string): void;
|
|
26
|
-
declare function checkSecrets(profile: string, secretsObject: Secrets, secretsFile: string): true | void;
|
|
27
|
-
declare function getScopesError(scopesFile: string): string;
|
|
28
|
-
declare function getSecretsError(profile: string, secretsFile: string): string;
|
|
29
30
|
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/lib/secrets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/lib/secrets.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,qBAAqB,CAAC;AAa7B,iBAAS,SAAS,IAAI,MAAM,EAAE,CAM7B;AAED,iBAAS,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAO5C;AAED,iBAAe,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAYhJ;AAGD,iBAAe,mBAAmB,CAAC,WAAW,EAAE,UAAU,CAAC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;IAAE,OAAO,EAAG,OAAO,CAAC;IAAC,eAAe,CAAC,EAAG,MAAM,CAAA;CAAE,CAAC,CAkBtI;AAED,iBAAe,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAmDzM;AAED,iBAAS,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAMhD;AAED,iBAAS,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI,CAKxF;AAED,iBAAS,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAKlD;AAED,iBAAS,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAmCrE;AAED,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,CAAC;;;;;;;;;;;;AACzD,wBAAmK"}
|
package/dist/lib/secrets.js
CHANGED
|
@@ -13,7 +13,6 @@ require("@anmiles/prototypes");
|
|
|
13
13
|
const paths_1 = require("./paths");
|
|
14
14
|
const renderer_1 = require("./renderer");
|
|
15
15
|
const secrets_1 = __importDefault(require("./secrets"));
|
|
16
|
-
exports.default = { getScopes, getSecrets, getCredentials, validateCredentials, createCredentials, deleteCredentials, checkSecrets, getSecretsError, getScopesError };
|
|
17
16
|
const port = 6006;
|
|
18
17
|
const host = `localhost:${port}`;
|
|
19
18
|
const startURI = `http://${host}/`;
|
|
@@ -23,14 +22,14 @@ const serverRetryInterval = 1000;
|
|
|
23
22
|
function getScopes() {
|
|
24
23
|
const scopesFile = (0, paths_1.getScopesFile)();
|
|
25
24
|
const scopes = fs_1.default.getJSON(scopesFile, () => {
|
|
26
|
-
throw secrets_1.default.getScopesError(scopesFile);
|
|
25
|
+
throw new Error(secrets_1.default.getScopesError(scopesFile));
|
|
27
26
|
});
|
|
28
27
|
return scopes;
|
|
29
28
|
}
|
|
30
29
|
function getSecrets(profile) {
|
|
31
30
|
const secretsFile = (0, paths_1.getSecretsFile)(profile);
|
|
32
31
|
const secretsObject = fs_1.default.getJSON(secretsFile, () => {
|
|
33
|
-
throw secrets_1.default.getSecretsError(profile, secretsFile);
|
|
32
|
+
throw new Error(secrets_1.default.getSecretsError(profile, secretsFile));
|
|
34
33
|
});
|
|
35
34
|
secrets_1.default.checkSecrets(profile, secretsObject, secretsFile);
|
|
36
35
|
return secretsObject;
|
|
@@ -44,11 +43,11 @@ async function getCredentials(profile, auth, options) {
|
|
|
44
43
|
return fs_1.default.getJSONAsync(credentialsFile, async () => {
|
|
45
44
|
const refreshToken = fs_1.default.existsSync(credentialsFile) ? fs_1.default.readJSON(credentialsFile).refresh_token : undefined;
|
|
46
45
|
const credentials = await secrets_1.default.createCredentials(profile, auth, options, refreshToken ? undefined : 'consent');
|
|
47
|
-
// eslint-disable-next-line camelcase
|
|
48
46
|
return { refresh_token: refreshToken, ...credentials };
|
|
49
47
|
}, secrets_1.default.validateCredentials);
|
|
50
48
|
}
|
|
51
49
|
exports.getCredentials = getCredentials;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/require-await -- pass sync function into async context
|
|
52
51
|
async function validateCredentials(credentials) {
|
|
53
52
|
if (!credentials.access_token) {
|
|
54
53
|
return { isValid: false, validationError: 'Credentials does not have access_token' };
|
|
@@ -65,17 +64,16 @@ async function validateCredentials(credentials) {
|
|
|
65
64
|
return { isValid: true };
|
|
66
65
|
}
|
|
67
66
|
async function createCredentials(profile, auth, options, prompt) {
|
|
68
|
-
const scope = options?.scopes
|
|
67
|
+
const scope = options?.scopes ?? secrets_1.default.getScopes();
|
|
69
68
|
return new Promise((resolve) => {
|
|
70
69
|
const authUrl = auth.generateAuthUrl({
|
|
71
|
-
// eslint-disable-next-line camelcase
|
|
72
70
|
access_type: 'offline',
|
|
73
71
|
prompt,
|
|
74
72
|
scope,
|
|
75
73
|
});
|
|
76
74
|
const server = http_1.default.createServer();
|
|
77
75
|
(0, server_destroy_1.default)(server);
|
|
78
|
-
server.on('request',
|
|
76
|
+
server.on('request', (request, response) => {
|
|
79
77
|
if (!request.url) {
|
|
80
78
|
response.end('');
|
|
81
79
|
return;
|
|
@@ -88,8 +86,10 @@ async function createCredentials(profile, auth, options, prompt) {
|
|
|
88
86
|
}
|
|
89
87
|
response.end((0, renderer_1.renderDone)({ profile }));
|
|
90
88
|
server.destroy();
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
void (async () => {
|
|
90
|
+
const { tokens } = await auth.getToken(code);
|
|
91
|
+
resolve(tokens);
|
|
92
|
+
})();
|
|
93
93
|
});
|
|
94
94
|
server.on('error', (error) => {
|
|
95
95
|
if (error.code === 'EADDRINUSE') {
|
|
@@ -99,9 +99,9 @@ async function createCredentials(profile, auth, options, prompt) {
|
|
|
99
99
|
throw error;
|
|
100
100
|
}
|
|
101
101
|
});
|
|
102
|
-
server.once('listening',
|
|
102
|
+
server.once('listening', () => {
|
|
103
103
|
(0, logger_1.warn)('Please check your browser for further actions');
|
|
104
|
-
(0, out_url_1.open)(startURI);
|
|
104
|
+
void (0, out_url_1.open)(startURI);
|
|
105
105
|
});
|
|
106
106
|
server.listen(port);
|
|
107
107
|
});
|
|
@@ -117,7 +117,7 @@ function checkSecrets(profile, secretsObject, secretsFile) {
|
|
|
117
117
|
if (secretsObject.web.redirect_uris[0] === callbackURI) {
|
|
118
118
|
return true;
|
|
119
119
|
}
|
|
120
|
-
throw `Error in credentials file: redirect URI should be ${callbackURI}.\n${secrets_1.default.getSecretsError(profile, secretsFile)}
|
|
120
|
+
throw new Error(`Error in credentials file: redirect URI should be ${callbackURI}.\n${secrets_1.default.getSecretsError(profile, secretsFile)}`);
|
|
121
121
|
}
|
|
122
122
|
function getScopesError(scopesFile) {
|
|
123
123
|
return [
|
|
@@ -161,4 +161,5 @@ function getSecretsError(profile, secretsFile) {
|
|
|
161
161
|
'Then start this script again',
|
|
162
162
|
].join('\n');
|
|
163
163
|
}
|
|
164
|
+
exports.default = { getScopes, getSecrets, getCredentials, validateCredentials, createCredentials, deleteCredentials, checkSecrets, getSecretsError, getScopesError };
|
|
164
165
|
//# sourceMappingURL=secrets.js.map
|