@anmiles/google-api-wrapper 1.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.
Files changed (62) hide show
  1. package/.eslintrc.js +91 -0
  2. package/.gitlab-ci.yml +118 -0
  3. package/.vscode/settings.json +10 -0
  4. package/CHANGELOG.md +14 -0
  5. package/LICENSE.md +21 -0
  6. package/README.md +35 -0
  7. package/coverage.config.js +8 -0
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.js +12 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/lib/auth.d.ts +9 -0
  12. package/dist/lib/auth.js +27 -0
  13. package/dist/lib/auth.js.map +1 -0
  14. package/dist/lib/data.d.ts +23 -0
  15. package/dist/lib/data.js +45 -0
  16. package/dist/lib/data.js.map +1 -0
  17. package/dist/lib/jsonLib.d.ts +14 -0
  18. package/dist/lib/jsonLib.js +48 -0
  19. package/dist/lib/jsonLib.js.map +1 -0
  20. package/dist/lib/logger.d.ts +12 -0
  21. package/dist/lib/logger.js +46 -0
  22. package/dist/lib/logger.js.map +1 -0
  23. package/dist/lib/paths.d.ts +14 -0
  24. package/dist/lib/paths.js +42 -0
  25. package/dist/lib/paths.js.map +1 -0
  26. package/dist/lib/profiles.d.ts +10 -0
  27. package/dist/lib/profiles.js +34 -0
  28. package/dist/lib/profiles.js.map +1 -0
  29. package/dist/lib/secrets.d.ts +16 -0
  30. package/dist/lib/secrets.js +95 -0
  31. package/dist/lib/secrets.js.map +1 -0
  32. package/dist/lib/sleep.d.ts +6 -0
  33. package/dist/lib/sleep.js +11 -0
  34. package/dist/lib/sleep.js.map +1 -0
  35. package/dist/types/index.d.ts +1 -0
  36. package/dist/types/index.js +18 -0
  37. package/dist/types/index.js.map +1 -0
  38. package/dist/types/secrets.d.ts +11 -0
  39. package/dist/types/secrets.js +3 -0
  40. package/dist/types/secrets.js.map +1 -0
  41. package/jest.config.js +22 -0
  42. package/package.json +50 -0
  43. package/src/index.ts +3 -0
  44. package/src/lib/__tests__/auth.test.ts +97 -0
  45. package/src/lib/__tests__/data.test.ts +154 -0
  46. package/src/lib/__tests__/jsonLib.test.ts +165 -0
  47. package/src/lib/__tests__/logger.test.ts +57 -0
  48. package/src/lib/__tests__/paths.test.ts +116 -0
  49. package/src/lib/__tests__/profiles.test.ts +117 -0
  50. package/src/lib/__tests__/secrets.test.ts +304 -0
  51. package/src/lib/__tests__/sleep.test.ts +17 -0
  52. package/src/lib/auth.ts +31 -0
  53. package/src/lib/data.ts +81 -0
  54. package/src/lib/jsonLib.ts +48 -0
  55. package/src/lib/logger.ts +21 -0
  56. package/src/lib/paths.ts +39 -0
  57. package/src/lib/profiles.ts +33 -0
  58. package/src/lib/secrets.ts +79 -0
  59. package/src/lib/sleep.ts +8 -0
  60. package/src/types/index.ts +1 -0
  61. package/src/types/secrets.ts +11 -0
  62. package/tsconfig.json +26 -0
package/.eslintrc.js ADDED
@@ -0,0 +1,91 @@
1
+ module.exports = {
2
+ root : true,
3
+ extends : [
4
+ 'eslint:recommended',
5
+ 'plugin:jest/recommended',
6
+ ],
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
+ };
package/.gitlab-ci.yml ADDED
@@ -0,0 +1,118 @@
1
+ default:
2
+ image: node:18.14
3
+
4
+ stages:
5
+ - setup
6
+ - build
7
+ - test
8
+ - coverage
9
+ - deploy
10
+
11
+ install:
12
+ stage: setup
13
+ cache:
14
+ key:
15
+ files:
16
+ - package-lock.json
17
+ prefix: ${CI_COMMIT_REF_SLUG}
18
+ paths:
19
+ - node_modules
20
+ policy: pull-push
21
+ script:
22
+ - npm ci
23
+ only:
24
+ - main
25
+ - merge_requests
26
+
27
+ build:
28
+ stage: build
29
+ cache:
30
+ key:
31
+ files:
32
+ - package-lock.json
33
+ prefix: ${CI_COMMIT_REF_SLUG}
34
+ paths:
35
+ - node_modules
36
+ policy: pull
37
+ script:
38
+ - npm run build
39
+ artifacts:
40
+ paths:
41
+ - dist/
42
+ only:
43
+ - main
44
+ - merge_requests
45
+
46
+ lint:
47
+ stage: test
48
+ cache:
49
+ key:
50
+ files:
51
+ - package-lock.json
52
+ prefix: ${CI_COMMIT_REF_SLUG}
53
+ paths:
54
+ - node_modules
55
+ policy: pull
56
+ script:
57
+ - npm run lint
58
+ only:
59
+ - main
60
+ - merge_requests
61
+
62
+ test:
63
+ stage: test
64
+ cache:
65
+ - key:
66
+ files:
67
+ - package-lock.json
68
+ prefix: ${CI_COMMIT_REF_SLUG}
69
+ paths:
70
+ - node_modules
71
+ policy: pull
72
+ - key: ${CI_COMMIT_REF_SLUG}_coverage
73
+ paths:
74
+ - coverage/**/*
75
+ policy: push
76
+ script:
77
+ - npm run test:ci
78
+ only:
79
+ - main
80
+ - merge_requests
81
+
82
+ coverage:
83
+ stage: coverage
84
+ cache:
85
+ - key:
86
+ files:
87
+ - package-lock.json
88
+ prefix: ${CI_COMMIT_REF_SLUG}
89
+ paths:
90
+ - node_modules
91
+ policy: pull
92
+ - key: ${CI_COMMIT_REF_SLUG}_coverage
93
+ paths:
94
+ - coverage/**/*
95
+ policy: pull
96
+ script:
97
+ - npm run test:report:coverage
98
+ only:
99
+ - main
100
+ - merge_requests
101
+
102
+ publish:
103
+ stage: deploy
104
+ cache:
105
+ key:
106
+ files:
107
+ - package-lock.json
108
+ prefix: ${CI_COMMIT_REF_SLUG}
109
+ paths:
110
+ - node_modules
111
+ policy: pull
112
+ script:
113
+ - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > .npmrc
114
+ - npm publish
115
+ when: manual
116
+ only:
117
+ - main
118
+ - merge_requests
@@ -0,0 +1,10 @@
1
+ {
2
+ "cSpell.words": [
3
+ "anmiles",
4
+ "cicd",
5
+ "colorette",
6
+ "linebreak",
7
+ "nycrc",
8
+ "Playlistitems"
9
+ ]
10
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0](../../tags/v1.0.0) - 2023-03-12
9
+ ### Changed
10
+ - First release
11
+
12
+ ## 0.0.1 - 2023-03-12
13
+ ### Added
14
+ - Initial commit
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Anatoliy Oblaukhov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # google-api-wrapper
2
+
3
+ Provides quick interface for getting google API data
4
+
5
+ ----
6
+
7
+ ## Usage
8
+
9
+ ``` bash
10
+ > $ npm install @anmiles/google-api-wrapper
11
+ > $ node ./auth.js
12
+ > $ node ./videos.js
13
+ ```
14
+
15
+ ``` js
16
+ /* auth.js */
17
+
18
+ import { createProfile, login } from '@anmiles/google-api-wrapper';
19
+
20
+ createProfile("username");
21
+ login("username");
22
+
23
+ ```
24
+
25
+ ``` js
26
+ /* videos.js */
27
+
28
+ import { getProfiles, getVideos } from '@anmiles/google-api-wrapper';
29
+
30
+ getProfiles().map(async (profile) => {
31
+ const videos = await getVideos(profile, { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 });
32
+ videos.forEach((video) => console.log(`Downloaded: ${video.snippet?.title}`));
33
+ });
34
+
35
+ ```
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ 'check-coverage' : true,
3
+ 'statements' : 100,
4
+ 'branches' : 100,
5
+ 'lines' : 100,
6
+ 'functions' : 100,
7
+ 'reporter' : [ 'html', 'text' ],
8
+ };
@@ -0,0 +1,3 @@
1
+ export { getEvents, getVideos } from './lib/data';
2
+ export { createProfile, getProfiles } from './lib/profiles';
3
+ export { login } from './lib/auth';
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.login = exports.getProfiles = exports.createProfile = exports.getVideos = exports.getEvents = void 0;
4
+ var data_1 = require("./lib/data");
5
+ Object.defineProperty(exports, "getEvents", { enumerable: true, get: function () { return data_1.getEvents; } });
6
+ Object.defineProperty(exports, "getVideos", { enumerable: true, get: function () { return data_1.getVideos; } });
7
+ var profiles_1 = require("./lib/profiles");
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
+ var auth_1 = require("./lib/auth");
11
+ Object.defineProperty(exports, "login", { enumerable: true, get: function () { return auth_1.login; } });
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAAkD;AAAzC,iGAAA,SAAS,OAAA;AAAE,iGAAA,SAAS,OAAA;AAC7B,2CAA4D;AAAnD,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnC,mCAAmC;AAA1B,6FAAA,KAAK,OAAA"}
@@ -0,0 +1,9 @@
1
+ import type GoogleApis from 'googleapis';
2
+ export { login, getAuth };
3
+ declare const _default: {
4
+ login: typeof login;
5
+ getAuth: typeof getAuth;
6
+ };
7
+ export default _default;
8
+ declare function login(profile?: string): Promise<void>;
9
+ declare function getAuth(profile: string): Promise<GoogleApis.Common.OAuth2Client>;
@@ -0,0 +1,27 @@
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 profiles_1 = require("./profiles");
9
+ const secrets_1 = require("./secrets");
10
+ const auth_1 = __importDefault(require("./auth"));
11
+ exports.default = { login, getAuth };
12
+ async function login(profile) {
13
+ const profiles = (0, profiles_1.getProfiles)().filter((p) => !profile || p === profile);
14
+ for (const profile of profiles) {
15
+ await auth_1.default.getAuth(profile);
16
+ }
17
+ }
18
+ exports.login = login;
19
+ async function getAuth(profile) {
20
+ const secrets = await (0, secrets_1.getSecrets)(profile);
21
+ const googleAuth = new googleapis_1.google.auth.OAuth2(secrets.web.client_id, secrets.web.client_secret, secrets.web.redirect_uris[0]);
22
+ const tokens = await (0, secrets_1.getCredentials)(profile, googleAuth);
23
+ googleAuth.setCredentials(tokens);
24
+ return googleAuth;
25
+ }
26
+ exports.getAuth = getAuth;
27
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,yCAAyC;AACzC,uCAAuD;AAEvD,kDAA0B;AAG1B,kBAAe,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;AAElC,KAAK,UAAU,KAAK,CAAC,OAAgB;IACpC,MAAM,QAAQ,GAAG,IAAA,sBAAW,GAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,IAAI,CAAC,KAAK,OAAO,CAAC,CAAC;IAExE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC/B,MAAM,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;KAC5B;AACF,CAAC;AATQ,sBAAK;AAWd,KAAK,UAAU,OAAO,CAAC,OAAe;IACrC,MAAM,OAAO,GAAG,MAAM,IAAA,oBAAU,EAAC,OAAO,CAAC,CAAC;IAE1C,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,CAAC,CAAC;IACzD,UAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,UAAU,CAAC;AACnB,CAAC;AAvBe,0BAAO"}
@@ -0,0 +1,23 @@
1
+ import type GoogleApis from 'googleapis';
2
+ export { getEvents, getVideos };
3
+ declare const _default: {
4
+ getData: typeof getData;
5
+ getEvents: typeof getEvents;
6
+ getVideos: typeof getVideos;
7
+ };
8
+ export default _default;
9
+ type CommonApi<TArgs, TResponse> = {
10
+ list: (params: TArgs & {
11
+ pageToken: string | undefined;
12
+ }, options?: GoogleApis.Common.MethodOptions | undefined) => Promise<GoogleApis.Common.GaxiosResponse<TResponse>>;
13
+ };
14
+ type CommonResponse<TItem> = {
15
+ items?: TItem[];
16
+ pageInfo?: {
17
+ totalResults?: number | null | undefined;
18
+ };
19
+ nextPageToken?: string | null | undefined;
20
+ };
21
+ declare function getData<TApi extends CommonApi<TArgs, TResponse>, TItem, TArgs, TResponse extends CommonResponse<TItem>>(api: TApi, args: TArgs): Promise<TItem[]>;
22
+ declare function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<GoogleApis.calendar_v3.Schema$Event[]>;
23
+ declare function getVideos(profile: string, args: GoogleApis.youtube_v3.Params$Resource$Playlistitems$List): Promise<GoogleApis.youtube_v3.Schema$PlaylistItem[]>;
@@ -0,0 +1,45 @@
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.getVideos = exports.getEvents = void 0;
7
+ const googleapis_1 = require("googleapis");
8
+ const auth_1 = require("./auth");
9
+ const data_1 = __importDefault(require("./data"));
10
+ const logger_1 = require("./logger");
11
+ const sleep_1 = require("./sleep");
12
+ exports.default = { getData, getEvents, getVideos };
13
+ const requestInterval = 300;
14
+ async function getData(api, args) {
15
+ var _a, _b;
16
+ const items = [];
17
+ let pageToken = undefined;
18
+ do {
19
+ const response = await api.list({ ...args, pageToken });
20
+ (_a = response.data.items) === null || _a === void 0 ? void 0 : _a.forEach((item) => items.push(item));
21
+ (0, logger_1.log)(`Getting items (${items.length} of ${((_b = response.data.pageInfo) === null || _b === void 0 ? void 0 : _b.totalResults) || 'many'})...`);
22
+ pageToken = response.data.nextPageToken;
23
+ await (0, sleep_1.sleep)(requestInterval);
24
+ } while (pageToken);
25
+ return items;
26
+ }
27
+ async function getEvents(profile, args) {
28
+ const googleAuth = await (0, auth_1.getAuth)(profile);
29
+ const { events } = googleapis_1.google.calendar({
30
+ version: 'v3',
31
+ auth: googleAuth,
32
+ });
33
+ return data_1.default.getData(events, args);
34
+ }
35
+ exports.getEvents = getEvents;
36
+ async function getVideos(profile, args) {
37
+ const googleAuth = await (0, auth_1.getAuth)(profile);
38
+ const { playlistItems } = googleapis_1.google.youtube({
39
+ version: 'v3',
40
+ auth: googleAuth,
41
+ });
42
+ return data_1.default.getData(playlistItems, args);
43
+ }
44
+ exports.getVideos = getVideos;
45
+ //# sourceMappingURL=data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/lib/data.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,iCAAiC;AACjC,kDAA0B;AAC1B,qCAA+B;AAC/B,mCAAgC;AAGhC,kBAAe,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,CAAC;AAiBjD,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B,KAAK,UAAU,OAAO,CAKpB,GAAS,EAAE,IAAW;;IACvB,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAAgD,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrG,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QACzD,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;QAC/F,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;QAExC,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;KAC7B,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,IAAwD;IACjG,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,EAAE,MAAM,EAAE,GAAG,mBAAM,CAAC,QAAQ,CAAC;QAClC,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;IAEH,OAAO,cAAI,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AAnDQ,8BAAS;AAqDlB,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,IAA8D;IACvG,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,EAAE,aAAa,EAAE,GAAG,mBAAM,CAAC,OAAO,CAAC;QACxC,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;IAEH,OAAO,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAC1C,CAAC;AA9DmB,8BAAS"}
@@ -0,0 +1,14 @@
1
+ export { getJSON, getJSONAsync, writeJSON };
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>>): T;
11
+ declare function getJSONAsync<T>(filename: string, createCallbackAsync: () => Promise<T>): 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;
@@ -0,0 +1,48 @@
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.writeJSON = exports.getJSONAsync = exports.getJSON = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const logger_1 = require("./logger");
9
+ const paths_1 = require("./paths");
10
+ const jsonLib_1 = __importDefault(require("./jsonLib"));
11
+ exports.default = { getJSON, getJSONAsync, writeJSON, readJSON, checkJSON };
12
+ function getJSON(filename, createCallback) {
13
+ if (fs_1.default.existsSync(filename)) {
14
+ return jsonLib_1.default.readJSON(filename);
15
+ }
16
+ const json = createCallback();
17
+ jsonLib_1.default.checkJSON(filename, json);
18
+ (0, paths_1.ensureFile)(filename);
19
+ jsonLib_1.default.writeJSON(filename, json);
20
+ return json;
21
+ }
22
+ exports.getJSON = getJSON;
23
+ async function getJSONAsync(filename, createCallbackAsync) {
24
+ if (fs_1.default.existsSync(filename)) {
25
+ return jsonLib_1.default.readJSON(filename);
26
+ }
27
+ const json = await createCallbackAsync();
28
+ jsonLib_1.default.checkJSON(filename, json);
29
+ jsonLib_1.default.writeJSON(filename, json);
30
+ return json;
31
+ }
32
+ exports.getJSONAsync = getJSONAsync;
33
+ function writeJSON(filename, json) {
34
+ const jsonString = JSON.stringify(json, null, ' ');
35
+ fs_1.default.writeFileSync(filename, jsonString);
36
+ }
37
+ exports.writeJSON = writeJSON;
38
+ function readJSON(filename) {
39
+ const jsonString = fs_1.default.readFileSync(filename).toString();
40
+ return JSON.parse(jsonString);
41
+ }
42
+ function checkJSON(filename, json) {
43
+ if (json) {
44
+ return;
45
+ }
46
+ (0, logger_1.error)(`File ${filename} doesn't exist and should be created with initial data, but function createCallback returned nothing`);
47
+ }
48
+ //# sourceMappingURL=jsonLib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonLib.js","sourceRoot":"","sources":["../../src/lib/jsonLib.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,qCAAiC;AACjC,mCAAqC;AAErC,wDAAgC;AAGhC,kBAAe,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;AAEzE,SAAS,OAAO,CAAI,QAAgB,EAAE,cAA8C;IACnF,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC5B,OAAO,iBAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAClC;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;AAbQ,0BAAO;AAehB,KAAK,UAAU,YAAY,CAAI,QAAgB,EAAE,mBAAqC;IACrF,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC5B,OAAO,iBAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;KAClC;IAED,MAAM,IAAI,GAAG,MAAM,mBAAmB,EAAE,CAAC;IACzC,iBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClC,iBAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC;AACb,CAAC;AAxBiB,oCAAY;AA0B9B,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;AA7B+B,8BAAS;AA+BzC,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;AAED,SAAS,SAAS,CAAI,QAAgB,EAAE,IAAO;IAC9C,IAAI,IAAI,EAAE;QACT,OAAO;KACP;IACD,IAAA,cAAK,EAAC,QAAQ,QAAQ,sGAAsG,CAAC,CAAC;AAC/H,CAAC"}
@@ -0,0 +1,12 @@
1
+ export { log, info, warn, error };
2
+ declare const _default: {
3
+ log: typeof log;
4
+ info: typeof info;
5
+ warn: typeof warn;
6
+ error: typeof error;
7
+ };
8
+ export default _default;
9
+ declare function log(message: string): void;
10
+ declare function info(message: string): void;
11
+ declare function warn(message: string): void;
12
+ declare function error(message: string): never;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.error = exports.warn = exports.info = exports.log = void 0;
27
+ const colorette = __importStar(require("colorette"));
28
+ exports.default = { log, info, warn, error };
29
+ function log(message) {
30
+ console.log(message);
31
+ }
32
+ exports.log = log;
33
+ function info(message) {
34
+ console.log(colorette.greenBright(message));
35
+ }
36
+ exports.info = info;
37
+ function warn(message) {
38
+ console.warn(colorette.yellowBright(message));
39
+ }
40
+ exports.warn = warn;
41
+ function error(message) {
42
+ console.error(`${colorette.redBright(message)}\n`);
43
+ process.exit(1);
44
+ }
45
+ exports.error = error;
46
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAGvC,kBAAe,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAE1C,SAAS,GAAG,CAAC,OAAe;IAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC;AALQ,kBAAG;AAOZ,SAAS,IAAI,CAAC,OAAe;IAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7C,CAAC;AATa,oBAAI;AAWlB,SAAS,IAAI,CAAC,OAAe;IAC5B,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AAC/C,CAAC;AAbmB,oBAAI;AAexB,SAAS,KAAK,CAAC,OAAe;IAC7B,OAAO,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACjB,CAAC;AAlByB,sBAAK"}
@@ -0,0 +1,14 @@
1
+ export { ensureDir, ensureFile, getProfilesFile, getSecretsFile, getCredentialsFile };
2
+ declare const _default: {
3
+ ensureDir: typeof ensureDir;
4
+ ensureFile: typeof ensureFile;
5
+ getProfilesFile: typeof getProfilesFile;
6
+ getSecretsFile: typeof getSecretsFile;
7
+ getCredentialsFile: typeof getCredentialsFile;
8
+ };
9
+ export default _default;
10
+ declare function ensureDir(dirPath: string): string;
11
+ declare function ensureFile(filePath: string): string;
12
+ declare function getProfilesFile(): string;
13
+ declare function getSecretsFile(profile: string): string;
14
+ declare function getCredentialsFile(profile: string): string;
@@ -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.getCredentialsFile = exports.getSecretsFile = exports.getProfilesFile = exports.ensureFile = exports.ensureDir = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const paths_1 = __importDefault(require("./paths"));
10
+ exports.default = { ensureDir, ensureFile, getProfilesFile, getSecretsFile, getCredentialsFile };
11
+ const dirPaths = {
12
+ input: 'input',
13
+ secrets: 'secrets',
14
+ };
15
+ function ensureDir(dirPath) {
16
+ if (!fs_1.default.existsSync(dirPath)) {
17
+ fs_1.default.mkdirSync(dirPath, { recursive: true });
18
+ }
19
+ return dirPath;
20
+ }
21
+ exports.ensureDir = ensureDir;
22
+ function ensureFile(filePath) {
23
+ paths_1.default.ensureDir(path_1.default.dirname(filePath));
24
+ if (!fs_1.default.existsSync(filePath)) {
25
+ fs_1.default.writeFileSync(filePath, '');
26
+ }
27
+ return filePath;
28
+ }
29
+ exports.ensureFile = ensureFile;
30
+ function getProfilesFile() {
31
+ return path_1.default.join(dirPaths.input, 'profiles.json');
32
+ }
33
+ exports.getProfilesFile = getProfilesFile;
34
+ function getSecretsFile(profile) {
35
+ return path_1.default.join(dirPaths.secrets, `${profile}.json`);
36
+ }
37
+ exports.getSecretsFile = getSecretsFile;
38
+ function getCredentialsFile(profile) {
39
+ return path_1.default.join(dirPaths.secrets, `${profile}.credentials.json`);
40
+ }
41
+ exports.getCredentialsFile = getCredentialsFile;
42
+ //# sourceMappingURL=paths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/lib/paths.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,oDAA4B;AAG5B,kBAAe,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC;AAE9F,MAAM,QAAQ,GAAG;IAChB,KAAK,EAAK,OAAO;IACjB,OAAO,EAAG,SAAS;CACnB,CAAC;AAEF,SAAS,SAAS,CAAC,OAAe;IACjC,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;QAC5B,YAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAG,IAAI,EAAE,CAAC,CAAC;KAC5C;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAbQ,8BAAS;AAelB,SAAS,UAAU,CAAC,QAAgB;IACnC,eAAK,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAExC,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC7B,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;KAC/B;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC;AAtBmB,gCAAU;AAwB9B,SAAS,eAAe;IACvB,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC;AACnD,CAAC;AA1B+B,0CAAe;AA4B/C,SAAS,cAAc,CAAC,OAAe;IACtC,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,OAAO,CAAC,CAAC;AACvD,CAAC;AA9BgD,wCAAc;AAgC/D,SAAS,kBAAkB,CAAC,OAAe;IAC1C,OAAO,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,OAAO,mBAAmB,CAAC,CAAC;AACnE,CAAC;AAlCgE,gDAAkB"}
@@ -0,0 +1,10 @@
1
+ export { getProfiles, setProfiles, createProfile };
2
+ declare const _default: {
3
+ getProfiles: typeof getProfiles;
4
+ setProfiles: typeof setProfiles;
5
+ createProfile: typeof createProfile;
6
+ };
7
+ export default _default;
8
+ declare function getProfiles(): string[];
9
+ declare function setProfiles(profiles: string[]): void;
10
+ declare function createProfile(profile: string): void;