@anmiles/google-api-wrapper 2.0.1 → 2.1.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.
@@ -1,8 +1,10 @@
1
1
  {
2
2
  "cSpell.words": [
3
3
  "anmiles",
4
+ "Calendarlist",
4
5
  "cicd",
5
6
  "colorette",
7
+ "Gaxios",
6
8
  "linebreak",
7
9
  "nycrc",
8
10
  "Playlistitems"
package/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ 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
+ ## [2.1.1](../../tags/v2.1.1) - 2023-03-13
9
+ ### Changed
10
+ - Fixed exported types
11
+
12
+ ## [2.1.0](../../tags/v2.1.0) - 2023-03-13
13
+ ### Added
14
+ - Calendars list API
15
+ - Export shared `getItems` to use for any other APIs
16
+
8
17
  ## [2.0.1](../../tags/v2.0.1) - 2023-03-12
9
18
  ### Changed
10
19
  - Fixed exported types
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * as calendar from './lib/api/calendar';
2
2
  export * as youtube from './lib/api/youtube';
3
+ export { getItems } from './lib/api/shared';
3
4
  export { createProfile, getProfiles } from './lib/profiles';
4
5
  export { login } from './lib/auth';
package/dist/index.js CHANGED
@@ -23,9 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.login = exports.getProfiles = exports.createProfile = exports.youtube = exports.calendar = void 0;
26
+ exports.login = exports.getProfiles = exports.createProfile = exports.getItems = exports.youtube = exports.calendar = void 0;
27
27
  exports.calendar = __importStar(require("./lib/api/calendar"));
28
28
  exports.youtube = __importStar(require("./lib/api/youtube"));
29
+ var shared_1 = require("./lib/api/shared");
30
+ Object.defineProperty(exports, "getItems", { enumerable: true, get: function () { return shared_1.getItems; } });
29
31
  var profiles_1 = require("./lib/profiles");
30
32
  Object.defineProperty(exports, "createProfile", { enumerable: true, get: function () { return profiles_1.createProfile; } });
31
33
  Object.defineProperty(exports, "getProfiles", { enumerable: true, get: function () { return profiles_1.getProfiles; } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA+C;AAC/C,6DAA6C;AAC7C,2CAA4D;AAAnD,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnC,mCAAmC;AAA1B,6FAAA,KAAK,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+DAA+C;AAC/C,6DAA6C;AAC7C,2CAA4C;AAAnC,kGAAA,QAAQ,OAAA;AACjB,2CAA4D;AAAnD,yGAAA,aAAa,OAAA;AAAE,uGAAA,WAAW,OAAA;AACnC,mCAAmC;AAA1B,6FAAA,KAAK,OAAA"}
@@ -1,11 +1,13 @@
1
1
  import type GoogleApis from 'googleapis';
2
- export { getAPI, getEvents, setEvent };
2
+ export { getAPI, getEvents, getCalendars, setEvent };
3
3
  declare const _default: {
4
4
  getAPI: typeof getAPI;
5
5
  getEvents: typeof getEvents;
6
+ getCalendars: typeof getCalendars;
6
7
  setEvent: typeof setEvent;
7
8
  };
8
9
  export default _default;
9
10
  declare function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>;
11
+ declare function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List): Promise<unknown[]>;
10
12
  declare function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List): Promise<unknown[]>;
11
13
  declare function setEvent(profile: string, eventId: string | undefined, args: GoogleApis.calendar_v3.Params$Resource$Events$Update): Promise<void>;
@@ -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.setEvent = exports.getEvents = exports.getAPI = void 0;
6
+ exports.setEvent = exports.getCalendars = exports.getEvents = exports.getAPI = void 0;
7
7
  const googleapis_1 = require("googleapis");
8
8
  const auth_1 = require("../auth");
9
9
  const shared_1 = require("./shared");
10
10
  const calendar_1 = __importDefault(require("./calendar"));
11
- exports.default = { getAPI, getEvents, setEvent };
11
+ exports.default = { getAPI, getEvents, getCalendars, setEvent };
12
12
  async function getAPI(profile) {
13
13
  const googleAuth = await (0, auth_1.getAuth)(profile);
14
14
  return googleapis_1.google.calendar({
@@ -17,6 +17,11 @@ async function getAPI(profile) {
17
17
  });
18
18
  }
19
19
  exports.getAPI = getAPI;
20
+ async function getCalendars(profile, args) {
21
+ const api = await calendar_1.default.getAPI(profile);
22
+ return (0, shared_1.getItems)(api.calendarList, args);
23
+ }
24
+ exports.getCalendars = getCalendars;
20
25
  async function getEvents(profile, args) {
21
26
  const api = await calendar_1.default.getAPI(profile);
22
27
  return (0, shared_1.getItems)(api.events, args);
@@ -1 +1 @@
1
- {"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../../src/lib/api/calendar.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAoC;AAEpC,kCAAkC;AAClC,qCAAoC;AACpC,0DAAkC;AAGlC,kBAAe,EAAE,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AAE/C,KAAK,UAAU,MAAM,CAAC,OAAe;IACpC,MAAM,UAAU,GAAG,MAAM,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC;IAE1C,OAAO,mBAAM,CAAC,QAAQ,CAAC;QACtB,OAAO,EAAG,IAAI;QACd,IAAI,EAAM,UAAU;KACpB,CAAC,CAAC;AACJ,CAAC;AAVQ,wBAAM;AAWf,KAAK,UAAU,SAAS,CAAC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AC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,OAAO,IAAA,iBAAQ,EAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC;AApBgB,8BAAS;AAsB1B,KAAK,UAAU,QAAQ,CAAC,OAAe,EAAE,OAA2B,EAAE,IAA0D;IAC/H,MAAM,GAAG,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC3C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;AACzC,CAAC;AAzByC,4BAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anmiles/google-api-wrapper",
3
- "version": "2.0.1",
3
+ "version": "2.1.1",
4
4
  "description": "Provides quick interface for getting google API data",
5
5
  "keywords": [
6
6
  "google",
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * as calendar from './lib/api/calendar';
2
2
  export * as youtube from './lib/api/youtube';
3
+ export { getItems } from './lib/api/shared';
3
4
  export { createProfile, getProfiles } from './lib/profiles';
4
5
  export { login } from './lib/auth';
@@ -7,11 +7,11 @@ import apiHelpers from './apiHelpers';
7
7
 
8
8
  const original = jest.requireActual('../calendar').default as typeof calendar;
9
9
  jest.mock<Partial<typeof calendar>>('../calendar', () => ({
10
- getAPI : jest.fn().mockImplementation(async () => ({ events : api })),
10
+ getAPI : jest.fn().mockImplementation(async () => ({ calendarList : calendarsAPI, events : eventsAPI })),
11
11
  }));
12
12
 
13
13
  jest.mock<Partial<typeof shared>>('../shared', () => ({
14
- getItems : jest.fn().mockImplementation(async () => events),
14
+ getItems : jest.fn(),
15
15
  }));
16
16
 
17
17
  jest.mock<Partial<typeof fs>>('fs', () => ({
@@ -20,7 +20,7 @@ jest.mock<Partial<typeof fs>>('fs', () => ({
20
20
 
21
21
  jest.mock('googleapis', () => ({
22
22
  google : {
23
- calendar : jest.fn().mockImplementation(() => ({ events : api })),
23
+ calendar : jest.fn().mockImplementation(() => ({ calendarList : calendarsAPI, events : eventsAPI })),
24
24
  },
25
25
  }));
26
26
 
@@ -28,12 +28,27 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
28
28
  getAuth : jest.fn().mockImplementation(() => googleAuth),
29
29
  }));
30
30
 
31
+ const getItemsSpy = jest.spyOn(shared, 'getItems');
32
+
31
33
  const profile = 'username';
32
34
 
33
35
  const googleAuth = {
34
36
  setCredentials : jest.fn(),
35
37
  };
36
38
 
39
+ const calendars: Array<{ summary?: string, description?: string, hidden?: boolean }> = [
40
+ { summary : 'calendar 1', description : 'calendar 1 description', hidden : false },
41
+ { summary : 'calendar 2', description : 'calendar 2 description', hidden : undefined },
42
+ { summary : 'calendar 3', description : undefined, hidden : true },
43
+ { summary : 'calendar 4', description : undefined, hidden : undefined },
44
+ ];
45
+
46
+ const calendarsResponse = [
47
+ [ calendars[0], calendars[1] ],
48
+ null,
49
+ [ calendars[2], calendars[3] ],
50
+ ];
51
+
37
52
  const events: Array<{ summary?: string, source?: { url?: string, title?: string} }> = [
38
53
  { summary : 'event 1', source : { title : 'source 1', url : 'https://example.com' } },
39
54
  { summary : 'event 2', source : { title : 'source 2', url : undefined } },
@@ -53,8 +68,8 @@ const pageTokens = [
53
68
  'token2',
54
69
  ];
55
70
 
56
- const api = apiHelpers.getAPI(eventsResponse, pageTokens);
57
- const args = { timeMin : '2010-01-01T00:00:00', timeMax : '2019-12-31T23:59:59' };
71
+ const calendarsAPI = apiHelpers.getAPI(calendarsResponse, pageTokens);
72
+ const eventsAPI = apiHelpers.getAPI(eventsResponse, pageTokens);
58
73
 
59
74
  describe('src/lib/api/calendar', () => {
60
75
  describe('getAPI', () => {
@@ -73,11 +88,43 @@ describe('src/lib/api/calendar', () => {
73
88
  it('should return calendar api', async () => {
74
89
  const result = await original.getAPI(profile);
75
90
 
76
- expect(result).toEqual({ events : api });
91
+ expect(result).toEqual({ calendarList : calendarsAPI, events : eventsAPI });
92
+ });
93
+ });
94
+
95
+ describe('getCalendars', () => {
96
+ const args = { showHidden : true };
97
+
98
+ beforeEach(() => {
99
+ getItemsSpy.mockResolvedValue(calendars);
100
+ });
101
+
102
+ it('should get api', async () => {
103
+ await original.getCalendars(profile, args);
104
+
105
+ expect(calendar.getAPI).toBeCalledWith(profile);
106
+ });
107
+
108
+ it('should get items', async () => {
109
+ await original.getCalendars(profile, args);
110
+
111
+ expect(getItemsSpy).toBeCalledWith(calendarsAPI, args);
112
+ });
113
+
114
+ it('should return calendars', async () => {
115
+ const result = await original.getCalendars(profile, args);
116
+
117
+ expect(result).toEqual(calendars);
77
118
  });
78
119
  });
79
120
 
80
121
  describe('getEvents', () => {
122
+ const args = { timeMin : '2010-01-01T00:00:00', timeMax : '2019-12-31T23:59:59' };
123
+
124
+ beforeEach(() => {
125
+ getItemsSpy.mockResolvedValue(events);
126
+ });
127
+
81
128
  it('should get api', async () => {
82
129
  await original.getEvents(profile, args);
83
130
 
@@ -87,7 +134,7 @@ describe('src/lib/api/calendar', () => {
87
134
  it('should get items', async () => {
88
135
  await original.getEvents(profile, args);
89
136
 
90
- expect(shared.getItems).toBeCalledWith(api, args);
137
+ expect(getItemsSpy).toBeCalledWith(eventsAPI, args);
91
138
  });
92
139
 
93
140
  it('should return events', async () => {
@@ -98,19 +145,19 @@ describe('src/lib/api/calendar', () => {
98
145
  });
99
146
 
100
147
  describe('setEvent', () => {
101
- const eventId = 'eventId';
102
- const updateArgs = { requestBody : { summary : 'summary' } };
148
+ const eventId = 'eventId';
149
+ const args = { requestBody : { summary : 'summary' } };
103
150
 
104
151
  it('should get api', async () => {
105
- await original.setEvent(profile, eventId, updateArgs);
152
+ await original.setEvent(profile, eventId, args);
106
153
 
107
154
  expect(calendar.getAPI).toBeCalledWith(profile);
108
155
  });
109
156
 
110
157
  it('should set items', async () => {
111
- await original.setEvent(profile, eventId, updateArgs);
158
+ await original.setEvent(profile, eventId, args);
112
159
 
113
- expect(api.update).toBeCalledWith({ eventId, ...updateArgs });
160
+ expect(eventsAPI.update).toBeCalledWith({ eventId, ...args });
114
161
  });
115
162
  });
116
163
  });
@@ -7,11 +7,11 @@ import apiHelpers from './apiHelpers';
7
7
 
8
8
  const original = jest.requireActual('../youtube').default as typeof youtube;
9
9
  jest.mock<Partial<typeof youtube>>('../youtube', () => ({
10
- getAPI : jest.fn().mockImplementation(async () => ({ playlistItems : api })),
10
+ getAPI : jest.fn().mockImplementation(async () => ({ playlistItems : playlistItemsAPI })),
11
11
  }));
12
12
 
13
13
  jest.mock<Partial<typeof shared>>('../shared', () => ({
14
- getItems : jest.fn().mockImplementation(async () => playlistItems),
14
+ getItems : jest.fn(),
15
15
  }));
16
16
 
17
17
  jest.mock<Partial<typeof fs>>('fs', () => ({
@@ -20,7 +20,7 @@ jest.mock<Partial<typeof fs>>('fs', () => ({
20
20
 
21
21
  jest.mock('googleapis', () => ({
22
22
  google : {
23
- youtube : jest.fn().mockImplementation(() => ({ playlistItems : api })),
23
+ youtube : jest.fn().mockImplementation(() => ({ playlistItems : playlistItemsAPI })),
24
24
  },
25
25
  }));
26
26
 
@@ -28,6 +28,8 @@ jest.mock<Partial<typeof auth>>('../../auth', () => ({
28
28
  getAuth : jest.fn().mockImplementation(() => googleAuth),
29
29
  }));
30
30
 
31
+ const getItemsSpy = jest.spyOn(shared, 'getItems');
32
+
31
33
  const profile = 'username';
32
34
 
33
35
  const googleAuth = {
@@ -53,8 +55,7 @@ const pageTokens = [
53
55
  'token2',
54
56
  ];
55
57
 
56
- const api = apiHelpers.getAPI(playlistItemsResponse, pageTokens);
57
- const args = { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 };
58
+ const playlistItemsAPI = apiHelpers.getAPI(playlistItemsResponse, pageTokens);
58
59
 
59
60
  describe('src/lib/api/youtube', () => {
60
61
  describe('getAPI', () => {
@@ -73,11 +74,17 @@ describe('src/lib/api/youtube', () => {
73
74
  it('should return youtube api', async () => {
74
75
  const result = await original.getAPI(profile);
75
76
 
76
- expect(result).toEqual({ playlistItems : api });
77
+ expect(result).toEqual({ playlistItems : playlistItemsAPI });
77
78
  });
78
79
  });
79
80
 
80
81
  describe('getPlaylistItems', () => {
82
+ const args = { playlistId : 'LL', part : [ 'snippet' ], maxResults : 50 };
83
+
84
+ beforeEach(() => {
85
+ getItemsSpy.mockResolvedValue(playlistItems);
86
+ });
87
+
81
88
  it('should get api', async () => {
82
89
  await original.getPlaylistItems(profile, args);
83
90
 
@@ -87,7 +94,7 @@ describe('src/lib/api/youtube', () => {
87
94
  it('should call getItems', async () => {
88
95
  await original.getPlaylistItems(profile, args);
89
96
 
90
- expect(shared.getItems).toBeCalledWith(api, args);
97
+ expect(getItemsSpy).toBeCalledWith(playlistItemsAPI, args);
91
98
  });
92
99
 
93
100
  it('should return videos', async () => {
@@ -4,8 +4,8 @@ import { getAuth } from '../auth';
4
4
  import { getItems } from './shared';
5
5
  import calendar from './calendar';
6
6
 
7
- export { getAPI, getEvents, setEvent };
8
- export default { getAPI, getEvents, setEvent };
7
+ export { getAPI, getEvents, getCalendars, setEvent };
8
+ export default { getAPI, getEvents, getCalendars, setEvent };
9
9
 
10
10
  async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar> {
11
11
  const googleAuth = await getAuth(profile);
@@ -15,6 +15,12 @@ async function getAPI(profile: string): Promise<GoogleApis.calendar_v3.Calendar>
15
15
  auth : googleAuth,
16
16
  });
17
17
  }
18
+
19
+ async function getCalendars(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Calendarlist$List) {
20
+ const api = await calendar.getAPI(profile);
21
+ return getItems(api.calendarList, args);
22
+ }
23
+
18
24
  async function getEvents(profile: string, args: GoogleApis.calendar_v3.Params$Resource$Events$List) {
19
25
  const api = await calendar.getAPI(profile);
20
26
  return getItems(api.events, args);