@anmiles/google-api-wrapper 18.0.3 → 19.0.1
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/.nycrc.json +27 -0
- package/CHANGELOG.md +32 -21
- package/README.md +1 -1
- package/cspell.json +22 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/api.d.ts +5 -11
- package/dist/lib/api.d.ts.map +1 -1
- package/dist/lib/api.js +5 -6
- package/dist/lib/api.js.map +1 -1
- package/dist/lib/auth.d.ts +2 -9
- package/dist/lib/auth.d.ts.map +1 -1
- package/dist/lib/auth.js +3 -23
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/credentials/generator.d.ts +4 -0
- package/dist/lib/credentials/generator.d.ts.map +1 -0
- package/dist/lib/credentials/generator.js +60 -0
- package/dist/lib/credentials/generator.js.map +1 -0
- package/dist/lib/credentials/index.d.ts +5 -0
- package/dist/lib/credentials/index.d.ts.map +1 -0
- package/dist/lib/credentials/index.js +42 -0
- package/dist/lib/credentials/index.js.map +1 -0
- package/dist/lib/credentials/validator.d.ts +7 -0
- package/dist/lib/credentials/validator.d.ts.map +1 -0
- package/dist/lib/credentials/validator.js +20 -0
- package/dist/lib/credentials/validator.js.map +1 -0
- package/dist/lib/login.d.ts +3 -0
- package/dist/lib/login.d.ts.map +1 -0
- package/dist/lib/login.js +19 -0
- package/dist/lib/login.js.map +1 -0
- package/dist/lib/profiles.d.ts +4 -12
- package/dist/lib/profiles.d.ts.map +1 -1
- package/dist/lib/profiles.js +8 -11
- package/dist/lib/profiles.js.map +1 -1
- package/dist/lib/renderer.d.ts +7 -25
- package/dist/lib/renderer.d.ts.map +1 -1
- package/dist/lib/renderer.js +26 -23
- package/dist/lib/renderer.js.map +1 -1
- package/dist/lib/scopes.d.ts +2 -0
- package/dist/lib/scopes.d.ts.map +1 -0
- package/dist/lib/scopes.js +22 -0
- package/dist/lib/scopes.js.map +1 -0
- package/dist/lib/secrets.d.ts +2 -28
- package/dist/lib/secrets.d.ts.map +1 -1
- package/dist/lib/secrets.js +15 -115
- package/dist/lib/secrets.js.map +1 -1
- package/dist/lib/utils/paths.d.ts +7 -0
- package/dist/lib/utils/paths.d.ts.map +1 -0
- package/dist/lib/{paths.js → utils/paths.js} +6 -8
- package/dist/lib/utils/paths.js.map +1 -0
- package/dist/templates/auth.html +1 -1
- package/dist/templates/index.html +6 -1
- package/dist/templates/page.html +1 -2
- package/dist/templates/script.html +0 -0
- package/{src/templates/css.html → dist/templates/style.html} +2 -2
- package/dist/types/options.d.ts +2 -3
- package/dist/types/options.d.ts.map +1 -1
- package/dist/types/secrets.d.ts +1 -2
- package/dist/types/secrets.d.ts.map +1 -1
- package/eslint.config.mts +43 -0
- package/jest.config.js +9 -9
- package/package.json +40 -30
- package/src/index.ts +3 -2
- package/src/lib/__tests__/__snapshots__/renderer.test.ts.snap +273 -0
- package/src/lib/__tests__/__snapshots__/scopes.test.ts.snap +6 -0
- package/src/lib/__tests__/__snapshots__/secrets.test.ts.snap +38 -0
- package/src/lib/__tests__/api.test.ts +72 -74
- package/src/lib/__tests__/auth.test.ts +38 -114
- package/src/lib/__tests__/login.test.ts +71 -0
- package/src/lib/__tests__/profiles.test.ts +50 -93
- package/src/lib/__tests__/renderer.test.ts +16 -89
- package/src/lib/__tests__/scopes.test.ts +41 -0
- package/src/lib/__tests__/secrets.test.ts +47 -541
- package/src/lib/api.ts +19 -21
- package/src/lib/auth.ts +5 -25
- package/src/lib/credentials/__tests__/generator.test.ts +249 -0
- package/src/lib/credentials/__tests__/index.test.ts +213 -0
- package/src/lib/credentials/__tests__/validator.test.ts +43 -0
- package/src/lib/credentials/generator.ts +70 -0
- package/src/lib/credentials/index.ts +50 -0
- package/src/lib/credentials/validator.ts +29 -0
- package/src/lib/login.ts +22 -0
- package/src/lib/profiles.ts +9 -12
- package/src/lib/renderer.ts +32 -27
- package/src/lib/scopes.ts +18 -0
- package/src/lib/secrets.ts +21 -141
- package/src/lib/utils/paths.ts +30 -0
- package/src/templates/auth.html +1 -1
- package/src/templates/index.html +6 -1
- package/src/templates/page.html +1 -2
- package/src/templates/script.html +0 -0
- package/{dist/templates/css.html → src/templates/style.html} +2 -2
- package/src/types/options.ts +5 -7
- package/src/types/secrets.ts +8 -10
- package/tsconfig.build.json +6 -0
- package/tsconfig.json +0 -5
- package/tsconfig.test.json +1 -1
- package/.eslintignore +0 -2
- package/.eslintrc.js +0 -30
- package/.vscode/settings.json +0 -9
- package/coverage.config.js +0 -8
- package/dist/lib/paths.d.ts +0 -16
- package/dist/lib/paths.d.ts.map +0 -1
- package/dist/lib/paths.js.map +0 -1
- package/src/lib/__tests__/paths.test.ts +0 -77
- package/src/lib/paths.ts +0 -32
package/.nycrc.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"all": true,
|
|
3
|
+
"check-coverage" : true,
|
|
4
|
+
|
|
5
|
+
"statements" : 100,
|
|
6
|
+
"branches" : 100,
|
|
7
|
+
"lines" : 100,
|
|
8
|
+
"functions" : 100,
|
|
9
|
+
|
|
10
|
+
"report-dir" : "./coverage",
|
|
11
|
+
"temp-dir" : "./coverage",
|
|
12
|
+
|
|
13
|
+
"reporter" : [
|
|
14
|
+
"text",
|
|
15
|
+
"html"
|
|
16
|
+
],
|
|
17
|
+
"extension": [
|
|
18
|
+
".js",
|
|
19
|
+
".mjs",
|
|
20
|
+
".cjs",
|
|
21
|
+
".jsx",
|
|
22
|
+
".ts",
|
|
23
|
+
".cts",
|
|
24
|
+
".mts",
|
|
25
|
+
".tsx"
|
|
26
|
+
]
|
|
27
|
+
}
|
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ 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
|
+
## [19.0.1](../../tags/v19.0.1) - 2025-05-19
|
|
9
|
+
### Changed
|
|
10
|
+
- Fixed expecting refresh_token in temporary credentials
|
|
11
|
+
|
|
12
|
+
## [19.0.0](../../tags/v19.0.0) - 2025-05-18
|
|
13
|
+
__(BREAKING) Dropped support for NodeJS 18 (EOL). Minimum required version is now NodeJS 20.__
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- Migrated to NodeJS 20.19
|
|
17
|
+
- Migrated to ESLint V9 flat configs
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
8
20
|
## [18.0.3](../../tags/v18.0.3) - 2024-04-03
|
|
9
21
|
### Changed
|
|
10
22
|
- Restructuring * reorganize HTML
|
|
@@ -56,16 +68,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
56
68
|
- Do not import all existing google APIs from one module
|
|
57
69
|
|
|
58
70
|
#### Before:
|
|
59
|
-
```
|
|
71
|
+
``` typescript
|
|
60
72
|
const calendarAPI = getAPI('calendar', profile);
|
|
61
73
|
```
|
|
62
74
|
#### After:
|
|
63
|
-
```
|
|
75
|
+
``` typescript
|
|
64
76
|
import { calendar } from 'googleapis/build/src/apis/calendar';
|
|
65
77
|
const calendarAPI = getAPI((auth) => calendar({ version : 'v3', auth })),
|
|
66
78
|
```
|
|
67
79
|
|
|
68
|
-
|
|
69
80
|
## [16.0.1](../../tags/v16.0.1) - 2024-01-16
|
|
70
81
|
### Changed
|
|
71
82
|
- Argument in `createProfile` might be undefined
|
|
@@ -117,25 +128,25 @@ const calendarAPI = getAPI((auth) => calendar({ version : 'v3', auth })),
|
|
|
117
128
|
- All existing google APIs are now available
|
|
118
129
|
### Changed
|
|
119
130
|
- Single entry point for creating any APIs
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
- BEFORE:
|
|
132
|
+
``` typescript
|
|
133
|
+
import { getCalendarAPI } from '@anmiles/google-api-wrapper';
|
|
134
|
+
const calendarAPI = getCalendarAPI(profile);
|
|
135
|
+
```
|
|
136
|
+
- AFTER:
|
|
137
|
+
``` typescript
|
|
138
|
+
import { getAPI } from '@anmiles/google-api-wrapper';
|
|
139
|
+
const calendarAPI = getAPI('calendar', profile);
|
|
140
|
+
```
|
|
130
141
|
- Changed signature for `getItems`. Also explicit types are now redundant.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
142
|
+
- BEFORE:
|
|
143
|
+
``` typescript
|
|
144
|
+
const events = await getItems<GoogleApis.calendar_v3.Schema$Event, GoogleApis.calendar_v3.Params$Resource$Events$List>(calendarAPI.events, { ...args });
|
|
145
|
+
```
|
|
146
|
+
- AFTER:
|
|
147
|
+
``` typescript
|
|
148
|
+
const events = await getItems((api) => api.events, { ...args });
|
|
149
|
+
```
|
|
139
150
|
- In case of `invalid_grant` error, credentials are being removed and warning shown. Will need to create new credentials.
|
|
140
151
|
|
|
141
152
|
## [9.1.0](../../tags/v9.1.0) - 2023-05-26
|
package/README.md
CHANGED
package/cspell.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.2",
|
|
3
|
+
"enabled": true,
|
|
4
|
+
"language": "en",
|
|
5
|
+
"minWordLength": 4,
|
|
6
|
+
"enableGlobDot": true,
|
|
7
|
+
"useGitignore": true,
|
|
8
|
+
"ignorePaths": [
|
|
9
|
+
".git",
|
|
10
|
+
"**/*.snap",
|
|
11
|
+
"package-lock.json"
|
|
12
|
+
],
|
|
13
|
+
"words": [
|
|
14
|
+
"anmiles",
|
|
15
|
+
"anatoliy",
|
|
16
|
+
"oblaukhov",
|
|
17
|
+
"gaxios",
|
|
18
|
+
"googleusercontent",
|
|
19
|
+
"playlistitems"
|
|
20
|
+
],
|
|
21
|
+
"flagWords": []
|
|
22
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getAPI } from './lib/api';
|
|
2
|
-
export { createProfile,
|
|
3
|
-
export {
|
|
2
|
+
export { createProfile, filterProfiles, getProfiles } from './lib/profiles';
|
|
3
|
+
export { getAuth } from './lib/auth';
|
|
4
|
+
export { login } from './lib/login';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,cAAc,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* istanbul ignore file */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.login = exports.getAuth = exports.getProfiles = exports.filterProfiles = exports.createProfile = exports.getAPI = void 0;
|
|
5
5
|
var api_1 = require("./lib/api");
|
|
6
6
|
Object.defineProperty(exports, "getAPI", { enumerable: true, get: function () { return api_1.getAPI; } });
|
|
7
7
|
var profiles_1 = require("./lib/profiles");
|
|
8
8
|
Object.defineProperty(exports, "createProfile", { enumerable: true, get: function () { return profiles_1.createProfile; } });
|
|
9
|
-
Object.defineProperty(exports, "getProfiles", { enumerable: true, get: function () { return profiles_1.getProfiles; } });
|
|
10
9
|
Object.defineProperty(exports, "filterProfiles", { enumerable: true, get: function () { return profiles_1.filterProfiles; } });
|
|
10
|
+
Object.defineProperty(exports, "getProfiles", { enumerable: true, get: function () { return profiles_1.getProfiles; } });
|
|
11
11
|
var auth_1 = require("./lib/auth");
|
|
12
|
-
Object.defineProperty(exports, "login", { enumerable: true, get: function () { return auth_1.login; } });
|
|
13
12
|
Object.defineProperty(exports, "getAuth", { enumerable: true, get: function () { return auth_1.getAuth; } });
|
|
13
|
+
var login_1 = require("./lib/login");
|
|
14
|
+
Object.defineProperty(exports, "login", { enumerable: true, get: function () { return login_1.login; } });
|
|
14
15
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,0GAAA,cAAc,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnD,mCAAqC;AAA5B,+FAAA,OAAO,OAAA;AAChB,qCAAoC;AAA3B,8FAAA,KAAK,OAAA"}
|
package/dist/lib/api.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import '@anmiles/prototypes';
|
|
1
2
|
import type GoogleApis from 'googleapis';
|
|
2
3
|
import type { AuthOptions, CommonOptions } from '../types/options';
|
|
3
|
-
import '@anmiles/prototypes';
|
|
4
4
|
type ListParams = Record<string, unknown> & {
|
|
5
5
|
pageToken: string | undefined;
|
|
6
6
|
};
|
|
@@ -10,14 +10,14 @@ interface CommonAPI<TItem> {
|
|
|
10
10
|
(callback: (err: Error | null, res?: GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>> | null) => void): void;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
interface CommonResponse<TItem> {
|
|
13
|
+
export interface CommonResponse<TItem> {
|
|
14
14
|
items?: TItem[];
|
|
15
15
|
pageInfo?: {
|
|
16
16
|
totalResults?: number | null | undefined;
|
|
17
17
|
};
|
|
18
18
|
nextPageToken?: string | null | undefined;
|
|
19
19
|
}
|
|
20
|
-
declare class API<TGoogleAPI> {
|
|
20
|
+
export declare class API<TGoogleAPI> {
|
|
21
21
|
private readonly getter;
|
|
22
22
|
private readonly profile;
|
|
23
23
|
private readonly authOptions?;
|
|
@@ -27,12 +27,6 @@ declare class API<TGoogleAPI> {
|
|
|
27
27
|
init(): Promise<void>;
|
|
28
28
|
getItems<TItem>(selectAPI: (api: TGoogleAPI) => CommonAPI<TItem>, params: object, options?: CommonOptions): Promise<TItem[]>;
|
|
29
29
|
}
|
|
30
|
-
declare function getAPI<TGoogleAPI>(getter: (auth: GoogleApis.Common.OAuth2Client) => TGoogleAPI, profile: string, authOptions?: AuthOptions): Promise<API<TGoogleAPI>>;
|
|
31
|
-
export {
|
|
32
|
-
export type { CommonResponse };
|
|
33
|
-
declare const _default: {
|
|
34
|
-
getAPI: typeof getAPI;
|
|
35
|
-
API: typeof API;
|
|
36
|
-
};
|
|
37
|
-
export default _default;
|
|
30
|
+
export declare function getAPI<TGoogleAPI>(getter: (auth: GoogleApis.Common.OAuth2Client) => TGoogleAPI, profile: string, authOptions?: AuthOptions): Promise<API<TGoogleAPI>>;
|
|
31
|
+
export {};
|
|
38
32
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/lib/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/lib/api.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AC5B,OAAO,CAAC,IAAI,CAA6C;gBAGvC,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,KAAI,UAAU,EAC3D,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,WAAW,YAAA;IAGrC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAKrB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,GAAG,EAAE,UAAU,KAAI,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;CAyCjI;AAED,wBAAsB,MAAM,CAAC,UAAU,EACtC,MAAM,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC,YAAY,KAAI,UAAU,EAC3D,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAY1B"}
|
package/dist/lib/api.js
CHANGED
|
@@ -3,12 +3,13 @@ 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.API =
|
|
6
|
+
exports.API = void 0;
|
|
7
|
+
exports.getAPI = getAPI;
|
|
7
8
|
const logger_1 = require("@anmiles/logger");
|
|
9
|
+
require("@anmiles/prototypes");
|
|
8
10
|
const sleep_1 = __importDefault(require("@anmiles/sleep"));
|
|
9
11
|
const auth_1 = require("./auth");
|
|
10
|
-
const
|
|
11
|
-
require("@anmiles/prototypes");
|
|
12
|
+
const credentials_1 = require("./credentials");
|
|
12
13
|
const requestInterval = 300;
|
|
13
14
|
class API {
|
|
14
15
|
getter;
|
|
@@ -41,7 +42,7 @@ class API {
|
|
|
41
42
|
const { message } = Error.parse(ex);
|
|
42
43
|
if ((message === 'invalid_grant' || message === 'Invalid credentials') && !this.authOptions?.temporary) {
|
|
43
44
|
(0, logger_1.warn)('Access token stored is invalid, re-creating...');
|
|
44
|
-
(0,
|
|
45
|
+
(0, credentials_1.deleteCredentials)(this.profile);
|
|
45
46
|
await this.init();
|
|
46
47
|
return this.getItems(selectAPI, params, options);
|
|
47
48
|
}
|
|
@@ -71,6 +72,4 @@ async function getAPI(getter, profile, authOptions) {
|
|
|
71
72
|
await instance.init();
|
|
72
73
|
return instance;
|
|
73
74
|
}
|
|
74
|
-
exports.getAPI = getAPI;
|
|
75
|
-
exports.default = { getAPI, API };
|
|
76
75
|
//# sourceMappingURL=api.js.map
|
package/dist/lib/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/lib/api.ts"],"names":[],"mappings":";;;;;;AA8FA,wBAgBC;AA9GD,4CAA4C;AAC5C,+BAA6B;AAC7B,2DAAmC;AAKnC,iCAAiC;AACjC,+CAAkD;AAElD,MAAM,eAAe,GAAG,GAAG,CAAC;AA0B5B,MAAa,GAAG;IAKG;IACA;IACA;IANlB,GAAG,CAAyB;IACpB,IAAI,CAA6C;IAEzD,YACkB,MAA2D,EAC3D,OAAe,EACf,WAAyB;QAFzB,WAAM,GAAN,MAAM,CAAqD;QAC3D,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,CA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AM,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;AAxDD,kBAwDC;AAEM,KAAK,UAAU,MAAM,CAC3B,MAA2D,EAC3D,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"}
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import type GoogleApis from 'googleapis';
|
|
2
|
-
import type {
|
|
3
|
-
declare function
|
|
4
|
-
declare function getAuth(profile: string, options?: AuthOptions): Promise<GoogleApis.Common.OAuth2Client>;
|
|
5
|
-
export { login, getAuth };
|
|
6
|
-
declare const _default: {
|
|
7
|
-
login: typeof login;
|
|
8
|
-
getAuth: typeof getAuth;
|
|
9
|
-
};
|
|
10
|
-
export default _default;
|
|
2
|
+
import type { AuthOptions } from '../types/options';
|
|
3
|
+
export declare function getAuth(profile: string, options?: AuthOptions): Promise<GoogleApis.Common.OAuth2Client>;
|
|
11
4
|
//# 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,
|
|
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,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAKpD,wBAAsB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAa7G"}
|
package/dist/lib/auth.js
CHANGED
|
@@ -1,35 +1,15 @@
|
|
|
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.getAuth =
|
|
3
|
+
exports.getAuth = getAuth;
|
|
7
4
|
const googleapis_1 = require("googleapis");
|
|
8
|
-
const
|
|
9
|
-
const profiles_1 = require("./profiles");
|
|
5
|
+
const credentials_1 = require("./credentials");
|
|
10
6
|
const secrets_1 = require("./secrets");
|
|
11
|
-
const auth_1 = __importDefault(require("./auth"));
|
|
12
|
-
async function login(profile, options) {
|
|
13
|
-
const profiles = (0, profiles_1.getProfiles)().filter((p) => !profile || p === profile);
|
|
14
|
-
for (const profile of profiles) {
|
|
15
|
-
if (!options?.hideProgress) {
|
|
16
|
-
(0, logger_1.warn)(`${profile} - logging in...`);
|
|
17
|
-
}
|
|
18
|
-
await auth_1.default.getAuth(profile, options);
|
|
19
|
-
if (!options?.hideProgress) {
|
|
20
|
-
(0, logger_1.info)(`${profile} - logged in successfully`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
exports.login = login;
|
|
25
7
|
async function getAuth(profile, options) {
|
|
26
8
|
const secrets = (0, secrets_1.getSecrets)(profile);
|
|
27
9
|
const googleAuth = new googleapis_1.google.auth.OAuth2(secrets.web.client_id, secrets.web.client_secret, secrets.web.redirect_uris[0]);
|
|
28
|
-
const tokens = await (0,
|
|
10
|
+
const tokens = await (0, credentials_1.getCredentials)(profile, googleAuth, options);
|
|
29
11
|
googleAuth.setCredentials(tokens);
|
|
30
12
|
googleapis_1.google.options({ auth: googleAuth });
|
|
31
13
|
return googleAuth;
|
|
32
14
|
}
|
|
33
|
-
exports.getAuth = getAuth;
|
|
34
|
-
exports.default = { login, getAuth };
|
|
35
15
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;AAQA,0BAaC;AArBD,2CAAoC;AAKpC,+CAA+C;AAC/C,uCAAuC;AAEhC,KAAK,UAAU,OAAO,CAAC,OAAe,EAAE,OAAqB;IACnE,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,4BAAc,EAAC,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAClE,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAClC,mBAAM,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;IACrC,OAAO,UAAU,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { AuthOptions } from '../../types/options';
|
|
3
|
+
export declare function generateCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client, options?: AuthOptions, prompt?: GoogleApis.Auth.GenerateAuthUrlOpts['prompt']): Promise<GoogleApis.Auth.Credentials>;
|
|
4
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/lib/credentials/generator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAIzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AASvD,wBAAsB,mBAAmB,CACxC,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,YAAY,EAClC,OAAO,CAAC,EAAE,WAAW,EACrB,MAAM,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,GACpD,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAgDtC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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.generateCredentials = generateCredentials;
|
|
7
|
+
const http_1 = __importDefault(require("http"));
|
|
8
|
+
const logger_1 = require("@anmiles/logger");
|
|
9
|
+
const out_url_1 = require("out-url");
|
|
10
|
+
const server_destroy_1 = __importDefault(require("server-destroy"));
|
|
11
|
+
const renderer_1 = require("../renderer");
|
|
12
|
+
const scopes_1 = require("../scopes");
|
|
13
|
+
const port = 6006;
|
|
14
|
+
const host = `localhost:${port}`;
|
|
15
|
+
const startURI = `http://${host}/`;
|
|
16
|
+
const serverRetryInterval = 1000;
|
|
17
|
+
async function generateCredentials(profile, auth, options, prompt) {
|
|
18
|
+
const scope = options?.scopes ?? (0, scopes_1.getScopes)();
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
const authUrl = auth.generateAuthUrl({
|
|
21
|
+
access_type: 'offline',
|
|
22
|
+
prompt,
|
|
23
|
+
scope,
|
|
24
|
+
});
|
|
25
|
+
const server = http_1.default.createServer();
|
|
26
|
+
(0, server_destroy_1.default)(server);
|
|
27
|
+
server.on('request', (request, response) => {
|
|
28
|
+
if (!request.url) {
|
|
29
|
+
response.end('');
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const url = new URL(`http://${request.headers.host}${request.url}`);
|
|
33
|
+
const code = url.searchParams.get('code');
|
|
34
|
+
if (!code) {
|
|
35
|
+
response.end((0, renderer_1.renderAuth)({ profile, authUrl, scope }));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
response.end((0, renderer_1.renderDone)({ profile }));
|
|
39
|
+
server.destroy();
|
|
40
|
+
void (async () => {
|
|
41
|
+
const { tokens } = await auth.getToken(code);
|
|
42
|
+
resolve(tokens);
|
|
43
|
+
})();
|
|
44
|
+
});
|
|
45
|
+
server.on('error', (error) => {
|
|
46
|
+
if (error.code === 'EADDRINUSE') {
|
|
47
|
+
setTimeout(() => server.listen(port), serverRetryInterval);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
server.once('listening', () => {
|
|
54
|
+
(0, logger_1.warn)('Please check your browser for further actions');
|
|
55
|
+
void (0, out_url_1.open)(startURI);
|
|
56
|
+
});
|
|
57
|
+
server.listen(port);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../src/lib/credentials/generator.ts"],"names":[],"mappings":";;;;;AAgBA,kDAqDC;AArED,gDAAwB;AAExB,4CAAuC;AAEvC,qCAA+B;AAC/B,oEAA2C;AAG3C,0CAAqD;AACrD,sCAAsC;AAEtC,MAAM,IAAI,GAAkB,IAAI,CAAC;AACjC,MAAM,IAAI,GAAkB,aAAa,IAAI,EAAE,CAAC;AAChD,MAAM,QAAQ,GAAc,UAAU,IAAI,GAAG,CAAC;AAC9C,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAE1B,KAAK,UAAU,mBAAmB,CACxC,OAAe,EACf,IAAkC,EAClC,OAAqB,EACrB,MAAsD;IAEtD,MAAM,KAAK,GAAG,OAAO,EAAE,MAAM,IAAI,IAAA,kBAAS,GAAE,CAAC;IAE7C,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC;YACpC,WAAW,EAAE,SAAS;YACtB,MAAM;YACN,KAAK;SACL,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,cAAI,CAAC,YAAY,EAAE,CAAC;QACnC,IAAA,wBAAa,EAAC,MAAM,CAAC,CAAC;QAEtB,MAAM,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;YAC1C,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAClB,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACjB,OAAO;YACR,CAAC;YAED,MAAM,GAAG,GAAI,IAAI,GAAG,CAAC,UAAU,OAAO,C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5 @@
|
|
|
1
|
+
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { AuthOptions } from '../../types/options';
|
|
3
|
+
export declare function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials>;
|
|
4
|
+
export declare function deleteCredentials(profile: string): void;
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/credentials/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAMvD,wBAAsB,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,CA+BvJ;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAMvD"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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.getCredentials = getCredentials;
|
|
7
|
+
exports.deleteCredentials = deleteCredentials;
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const paths_1 = require("../utils/paths");
|
|
10
|
+
const generator_1 = require("./generator");
|
|
11
|
+
const validator_1 = require("./validator");
|
|
12
|
+
async function getCredentials(profile, auth, options) {
|
|
13
|
+
const credentialsFile = (0, paths_1.getCredentialsFile)(profile);
|
|
14
|
+
if (options?.temporary) {
|
|
15
|
+
const credentials = await (0, generator_1.generateCredentials)(profile, auth, options);
|
|
16
|
+
const validationResult = (0, validator_1.validateCredentials)(credentials, options);
|
|
17
|
+
if (!validationResult.isValid) {
|
|
18
|
+
throw new Error(validationResult.validationError);
|
|
19
|
+
}
|
|
20
|
+
return credentials;
|
|
21
|
+
}
|
|
22
|
+
return fs_1.default.getJSONAsync(credentialsFile, async () => {
|
|
23
|
+
const refreshToken = fs_1.default.existsSync(credentialsFile)
|
|
24
|
+
? fs_1.default.readJSON(credentialsFile).refresh_token
|
|
25
|
+
: undefined;
|
|
26
|
+
const credentials = await (0, generator_1.generateCredentials)(profile, auth, options, refreshToken
|
|
27
|
+
? undefined
|
|
28
|
+
: 'consent');
|
|
29
|
+
return {
|
|
30
|
+
refresh_token: refreshToken,
|
|
31
|
+
...credentials,
|
|
32
|
+
};
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
34
|
+
}, async (credentials) => (0, validator_1.validateCredentials)(credentials));
|
|
35
|
+
}
|
|
36
|
+
function deleteCredentials(profile) {
|
|
37
|
+
const credentialsFile = (0, paths_1.getCredentialsFile)(profile);
|
|
38
|
+
if (fs_1.default.existsSync(credentialsFile)) {
|
|
39
|
+
fs_1.default.rmSync(credentialsFile);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/credentials/index.ts"],"names":[],"mappings":";;;;;AAUA,wCA+BC;AAED,8CAMC;AAjDD,4CAAoB;AAKpB,0CAAoD;AAEpD,2CAAkD;AAClD,2CAAkD;AAE3C,KAAK,UAAU,cAAc,CAAC,OAAe,EAAE,IAAoC,EAAE,OAAqB;IAChH,MAAM,eAAe,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;IAEpD,IAAI,OAAO,EAAE,SAAS,EAAE,CAAC;QACxB,MAAM,WAAW,GAAQ,MAAM,IAAA,+BAAmB,EAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3E,MAAM,gBAAgB,GAAG,IAAA,+BAAmB,EAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAEnE,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;QACnD,CAAC;QAED,OAAO,WAAW,CAAC;IACpB,CAAC;IAED,OAAO,YAAE,CAAC,YAAY,CAAC,eAAe,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,YAAY,GAAG,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC;YAClD,CAAC,CAAC,YAAE,CAAC,QAAQ,CAA8B,eAAe,CAAC,CAAC,aAAa;YACzE,CAAC,CAAC,SAAS,CAAC;QAEb,MAAM,WAAW,GAAG,MAAM,IAAA,+BAAmB,EAAC,OAAO,EAAE,IAAI,EAAE,OAAO,EACnE,YAAY;YACX,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,SAAS,CACZ,CAAC;QAEF,OAAO;YACN,aAAa,EAAE,YAAY;YAC3B,GAAG,WAAW;SACd,CAAC;QACH,4DAA4D;IAC5D,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,CAAC,IAAA,+BAAmB,EAAC,WAAW,CAAC,CAAC,CAAC;AAC7D,CAAC;AAED,SAAgB,iBAAiB,CAAC,OAAe;IAChD,MAAM,eAAe,GAAG,IAAA,0BAAkB,EAAC,OAAO,CAAC,CAAC;IAEpD,IAAI,YAAE,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACpC,YAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAC5B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type GoogleApis from 'googleapis';
|
|
2
|
+
import type { AuthOptions } from '../../types/options';
|
|
3
|
+
export declare function validateCredentials(credentials: GoogleApis.Auth.Credentials, options?: AuthOptions): {
|
|
4
|
+
isValid: boolean;
|
|
5
|
+
validationError?: string;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../../../src/lib/credentials/validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,YAAY,CAAC;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,wBAAgB,mBAAmB,CAClC,WAAW,EAAE,UAAU,CAAC,IAAI,CAAC,WAAW,EACxC,OAAO,CAAC,EAAE,WAAW,GACnB;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,CAmBhD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateCredentials = validateCredentials;
|
|
4
|
+
const tokenExpiration = 7 * 24 * 60 * 60 * 1000;
|
|
5
|
+
function validateCredentials(credentials, options) {
|
|
6
|
+
if (!credentials.access_token) {
|
|
7
|
+
return { isValid: false, validationError: 'Credentials does not have access_token' };
|
|
8
|
+
}
|
|
9
|
+
if (!credentials.refresh_token && !options?.temporary) {
|
|
10
|
+
return { isValid: false, validationError: 'Credentials does not have refresh_token' };
|
|
11
|
+
}
|
|
12
|
+
if (!credentials.expiry_date) {
|
|
13
|
+
return { isValid: false, validationError: 'Credentials does not have expiry_date' };
|
|
14
|
+
}
|
|
15
|
+
if (new Date().getTime() - credentials.expiry_date >= tokenExpiration) {
|
|
16
|
+
return { isValid: false, validationError: 'Credentials expired' };
|
|
17
|
+
}
|
|
18
|
+
return { isValid: true };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../../src/lib/credentials/validator.ts"],"names":[],"mappings":";;AAMA,kDAsBC;AAxBD,MAAM,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEhD,SAAgB,mBAAmB,CAClC,WAAwC,EACxC,OAAqB;IAGrB,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;QAC/B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,wCAAwC,EAAE,CAAC;IACtF,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,aAAa,IAAI,CAAC,OAAO,EAAE,SAAS,EAAE,CAAC;QACvD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,yCAAyC,EAAE,CAAC;IACvF,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;QAC9B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,uCAAuC,EAAE,CAAC;IACrF,CAAC;IAED,IAAI,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC,WAAW,IAAI,eAAe,EAAE,CAAC;QACvE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,qBAAqB,EAAE,CAAC;IACnE,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/lib/login.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAKnE,wBAAsB,KAAK,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAclG"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.login = login;
|
|
4
|
+
const logger_1 = require("@anmiles/logger");
|
|
5
|
+
const auth_1 = require("./auth");
|
|
6
|
+
const profiles_1 = require("./profiles");
|
|
7
|
+
async function login(profile, options) {
|
|
8
|
+
const profiles = (0, profiles_1.getProfiles)().filter((p) => !profile || p === profile);
|
|
9
|
+
for (const profile of profiles) {
|
|
10
|
+
if (!options?.hideProgress) {
|
|
11
|
+
(0, logger_1.warn)(`${profile} - logging in...`);
|
|
12
|
+
}
|
|
13
|
+
await (0, auth_1.getAuth)(profile, options);
|
|
14
|
+
if (!options?.hideProgress) {
|
|
15
|
+
(0, logger_1.info)(`${profile} - logged in successfully`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/lib/login.ts"],"names":[],"mappings":";;AAOA,sBAcC;AArBD,4CAA6C;AAI7C,iCAAiC;AACjC,yCAAyC;AAElC,KAAK,UAAU,KAAK,CAAC,OAAgB,EAAE,OAAqC;IAClF,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,IAAA,cAAO,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,CAAC;YAC5B,IAAA,aAAI,EAAC,GAAG,OAAO,2BAA2B,CAAC,CAAC;QAC7C,CAAC;IACF,CAAC;AACF,CAAC"}
|
package/dist/lib/profiles.d.ts
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
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[];
|
|
6
|
-
export { getProfiles, setProfiles, createProfile, filterProfiles };
|
|
7
|
-
declare const _default: {
|
|
8
|
-
getProfiles: typeof getProfiles;
|
|
9
|
-
setProfiles: typeof setProfiles;
|
|
10
|
-
createProfile: typeof createProfile;
|
|
11
|
-
filterProfiles: typeof filterProfiles;
|
|
12
|
-
};
|
|
13
|
-
export default _default;
|
|
2
|
+
export declare function getProfiles(): string[];
|
|
3
|
+
export declare function setProfiles(profiles: string[]): void;
|
|
4
|
+
export declare function createProfile(profile?: string): void;
|
|
5
|
+
export declare function filterProfiles(profile?: string): string[];
|
|
14
6
|
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":"AAEA,OAAO,qBAAqB,CAAC;AAI7B,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAGtC;AAED,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAGpD;AAED,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAapD;AAED,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAgBzD"}
|