@anmiles/google-api-wrapper 14.0.0 → 14.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ 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
+ ## [14.1.0](../../tags/v14.1.0) - 2023-08-06
9
+ ### Added
10
+ - Filtering profiles
11
+
8
12
  ## [14.0.0](../../tags/v14.0.0) - 2023-06-11
9
13
  ### Added
10
14
  - Warn if trying to store non-readonly credentials in a file
@@ -21,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
21
25
  - All existing google APIs are now available
22
26
  ### Changed
23
27
  - Single entry point for creating any APIs
24
- - BEFORE:
28
+ - BEFORE:
25
29
  ```
26
30
  import { getCalendarAPI } from '@anmiles/google-api-wrapper';
27
31
  const calendarAPI = getCalendarAPI(profile);
@@ -32,7 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
32
36
  const calendarAPI = getAPI('calendar', profile);
33
37
  ```
34
38
  - Changed signature for `getItems`. Also explicit types are now redundant.
35
- - BEFORE:
39
+ - BEFORE:
36
40
  ```
37
41
  const events = await getItems<GoogleApis.calendar_v3.Schema$Event, GoogleApis.calendar_v3.Params$Resource$Events$List>(calendarAPI.events, { ...args });
38
42
  ```
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { getAPI } from './lib/api';
2
- export { createProfile, getProfiles } from './lib/profiles';
2
+ export { createProfile, getProfiles, filterProfiles } from './lib/profiles';
3
3
  export { login, getAuth } from './lib/auth';
package/dist/index.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAuth = exports.login = exports.getProfiles = exports.createProfile = exports.getAPI = void 0;
3
+ exports.getAuth = exports.login = exports.filterProfiles = exports.getProfiles = exports.createProfile = exports.getAPI = void 0;
4
4
  var api_1 = require("./lib/api");
5
5
  Object.defineProperty(exports, "getAPI", { enumerable: true, get: function () { return api_1.getAPI; } });
6
6
  var profiles_1 = require("./lib/profiles");
7
7
  Object.defineProperty(exports, "createProfile", { enumerable: true, get: function () { return profiles_1.createProfile; } });
8
8
  Object.defineProperty(exports, "getProfiles", { enumerable: true, get: function () { return profiles_1.getProfiles; } });
9
+ Object.defineProperty(exports, "filterProfiles", { enumerable: true, get: function () { return profiles_1.filterProfiles; } });
9
10
  var auth_1 = require("./lib/auth");
10
11
  Object.defineProperty(exports, "login", { enumerable: true, get: function () { return auth_1.login; } });
11
12
  Object.defineProperty(exports, "getAuth", { enumerable: true, get: function () { return auth_1.getAuth; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAAmC;AAA1B,6FAAA,MAAM,OAAA;AACf,2CAA4D;AAAnD,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnC,mCAA4C;AAAnC,6FAAA,KAAK,OAAA;AAAE,+FAAA,OAAO,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,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"}
@@ -1,11 +1,13 @@
1
1
  import '@anmiles/prototypes';
2
- export { getProfiles, setProfiles, createProfile };
2
+ export { getProfiles, setProfiles, createProfile, filterProfiles };
3
3
  declare const _default: {
4
4
  getProfiles: typeof getProfiles;
5
5
  setProfiles: typeof setProfiles;
6
6
  createProfile: typeof createProfile;
7
+ filterProfiles: typeof filterProfiles;
7
8
  };
8
9
  export default _default;
9
10
  declare function getProfiles(): string[];
10
11
  declare function setProfiles(profiles: string[]): void;
11
12
  declare function createProfile(profile: string): void;
13
+ declare function filterProfiles(profile?: string): string[];
@@ -3,12 +3,12 @@ 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.createProfile = exports.setProfiles = exports.getProfiles = void 0;
6
+ exports.filterProfiles = exports.createProfile = exports.setProfiles = exports.getProfiles = void 0;
7
7
  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 };
11
+ exports.default = { getProfiles, setProfiles, createProfile, filterProfiles };
12
12
  function getProfiles() {
13
13
  const profilesFile = (0, paths_1.getProfilesFile)();
14
14
  return fs_1.default.getJSON(profilesFile, () => []);
@@ -31,4 +31,18 @@ function createProfile(profile) {
31
31
  profiles_1.default.setProfiles(existingProfiles);
32
32
  }
33
33
  exports.createProfile = createProfile;
34
+ function filterProfiles(profile) {
35
+ const existingProfiles = profiles_1.default.getProfiles();
36
+ if (existingProfiles.length === 0) {
37
+ throw 'Please `npm run create` at least one profile';
38
+ }
39
+ if (!profile) {
40
+ return existingProfiles;
41
+ }
42
+ if (existingProfiles.includes(profile)) {
43
+ return [profile];
44
+ }
45
+ throw `Profile '${profile}' does not exist`;
46
+ }
47
+ exports.filterProfiles = filterProfiles;
34
48
  //# sourceMappingURL=profiles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/lib/profiles.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,+BAA6B;AAC7B,mCAA0C;AAE1C,0DAAkC;AAGlC,kBAAe,EAAE,W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,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC;AAXqB,kCAAW;AAajC,SAAS,aAAa,CAAC,OAAe;IACrC,IAAI,CAAC,OAAO,EAAE;QACb,MAAM,kFAAkF,CAAC;KACzF;IAED,MAAM,gBAAgB,GAAG,kBAAQ,CAAC,WAAW,EAAE,CAAC;IAEhD,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACvC,OAAO;KACP;IAED,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC/B,kBAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;AACxC,CAAC;AA1BkC,sCAAa;AA4BhD,SAAS,cAAc,CAAC,OAAgB;IACvC,MAAM,gBAAgB,GAAG,kBAAQ,CAAC,WAAW,EAAE,CAAC;IAEhD,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE;QAClC,MAAM,8CAA8C,CAAC;KACrD;IAED,IAAI,CAAC,OAAO,EAAE;QACb,OAAO,gBAAgB,CAAC;KACxB;IAED,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE;QACvC,OAAO,CAAE,OAAO,CAAE,CAAC;KACnB;IAED,MAAM,YAAY,OAAO,kBAAkB,CAAC;AAC7C,CAAC;AA5CiD,wCAAc"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anmiles/google-api-wrapper",
3
- "version": "14.0.0",
3
+ "version": "14.1.0",
4
4
  "description": "Provides quick interface for getting google API data",
5
5
  "keywords": [
6
6
  "google",
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { getAPI } from './lib/api';
2
- export { createProfile, getProfiles } from './lib/profiles';
2
+ export { createProfile, getProfiles, filterProfiles } from './lib/profiles';
3
3
  export { login, getAuth } from './lib/auth';
@@ -5,9 +5,10 @@ import paths from '../paths';
5
5
  import profiles from '../profiles';
6
6
  const original = jest.requireActual('../profiles').default as typeof profiles;
7
7
  jest.mock<typeof profiles>('../profiles', () => ({
8
- getProfiles : jest.fn().mockImplementation(() => existingProfiles),
9
- setProfiles : jest.fn(),
10
- createProfile : jest.fn(),
8
+ getProfiles : jest.fn().mockImplementation(() => existingProfiles),
9
+ setProfiles : jest.fn(),
10
+ createProfile : jest.fn(),
11
+ filterProfiles : jest.fn(),
11
12
  }));
12
13
 
13
14
  jest.mock<Partial<typeof fs>>('fs', () => ({
@@ -26,13 +27,13 @@ jest.mock<Partial<typeof paths>>('../paths', () => ({
26
27
  getProfilesFile : jest.fn().mockImplementation(() => profilesFile),
27
28
  }));
28
29
 
29
- const json = { key : 'value' };
30
- const existingProfiles = [ 'username1', 'username2' ];
31
- const profilesFile = 'profilesFile';
32
- const profile1 = 'username1';
33
- const profile2 = 'username2';
34
- const allProfiles = [ profile1, profile2 ];
30
+ const json = { key : 'value' };
31
+ const profilesFile = 'profilesFile';
32
+ const profile1 = 'username1';
33
+ const profile2 = 'username2';
34
+ const allProfiles = [ profile1, profile2 ];
35
35
 
36
+ let existingProfiles: string[];
36
37
  let existingFiles: string[] = [];
37
38
 
38
39
  let getJSONSpy: jest.SpyInstance;
@@ -46,7 +47,9 @@ beforeAll(() => {
46
47
  beforeEach(() => {
47
48
  getJSONSpy.mockImplementation(() => json);
48
49
  writeJSONSpy.mockImplementation();
49
- existingFiles = [];
50
+
51
+ existingFiles = [];
52
+ existingProfiles = [ 'username1', 'username2' ];
50
53
  });
51
54
 
52
55
  afterAll(() => {
@@ -118,4 +121,40 @@ describe('src/lib/profiles', () => {
118
121
  expect(profiles.setProfiles).toHaveBeenCalledWith([ 'username1', 'username2', 'newProfile' ]);
119
122
  });
120
123
  });
124
+
125
+ describe('filterProfiles', () => {
126
+ it('should get profiles', () => {
127
+ original.filterProfiles();
128
+
129
+ expect(profiles.getProfiles).toHaveBeenCalled();
130
+ });
131
+
132
+ it('should output error if no profiles', () => {
133
+ existingProfiles = [];
134
+
135
+ const func = () => original.filterProfiles();
136
+
137
+ expect(func).toThrow('Please `npm run create` at least one profile');
138
+ });
139
+
140
+ it('should output error if profile does not exist', () => {
141
+ const newProfile = 'newProfile';
142
+
143
+ const func = () => original.filterProfiles(newProfile);
144
+
145
+ expect(func).toThrow(`Profile '${newProfile}' does not exist`);
146
+ });
147
+
148
+ it('should return array with requested profile if it exists', () => {
149
+ const found = original.filterProfiles(profile1);
150
+
151
+ expect(found).toEqual([ profile1 ]);
152
+ });
153
+
154
+ it('should return all profiles if nothing requested', () => {
155
+ const found = original.filterProfiles();
156
+
157
+ expect(found).toEqual(existingProfiles);
158
+ });
159
+ });
121
160
  });
@@ -4,8 +4,8 @@ import { getProfilesFile } from './paths';
4
4
 
5
5
  import profiles from './profiles';
6
6
 
7
- export { getProfiles, setProfiles, createProfile };
8
- export default { getProfiles, setProfiles, createProfile };
7
+ export { getProfiles, setProfiles, createProfile, filterProfiles };
8
+ export default { getProfiles, setProfiles, createProfile, filterProfiles };
9
9
 
10
10
  function getProfiles(): string[] {
11
11
  const profilesFile = getProfilesFile();
@@ -31,3 +31,21 @@ function createProfile(profile: string): void {
31
31
  existingProfiles.push(profile);
32
32
  profiles.setProfiles(existingProfiles);
33
33
  }
34
+
35
+ function filterProfiles(profile?: string): string[] {
36
+ const existingProfiles = profiles.getProfiles();
37
+
38
+ if (existingProfiles.length === 0) {
39
+ throw 'Please `npm run create` at least one profile';
40
+ }
41
+
42
+ if (!profile) {
43
+ return existingProfiles;
44
+ }
45
+
46
+ if (existingProfiles.includes(profile)) {
47
+ return [ profile ];
48
+ }
49
+
50
+ throw `Profile '${profile}' does not exist`;
51
+ }