@anmiles/google-api-wrapper 6.0.1 → 6.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
+ ## [6.1.0](../../tags/v6.1.0) - 2023-03-24
9
+ ### Added
10
+ - Overriding scopes for `getAuth` and `getAPI` functions
11
+
8
12
  ## [6.0.1](../../tags/v6.0.1) - 2023-03-20
9
13
  ### Changed
10
14
  - Improved types for `getItems` method
@@ -14,7 +14,7 @@ export default _default;
14
14
  declare function getScopes(): string[];
15
15
  declare function getSecrets(profile: string): Secrets;
16
16
  declare function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials>;
17
- declare function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client): Promise<GoogleApis.Auth.Credentials>;
17
+ declare function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials>;
18
18
  declare function checkSecrets(profile: string, secretsObject: Secrets, secretsFile: string): true | void;
19
19
  declare function getScopesError(scopesFile: string): string;
20
20
  declare function getSecretsError(profile: string, secretsFile: string): string;
@@ -51,12 +51,12 @@ exports.getSecrets = getSecrets;
51
51
  async function getCredentials(profile, auth, options) {
52
52
  const credentialsFile = (0, paths_1.getCredentialsFile)(profile);
53
53
  return (options === null || options === void 0 ? void 0 : options.temporary)
54
- ? secrets_1.default.createCredentials(profile, auth)
55
- : (0, jsonLib_1.getJSONAsync)(credentialsFile, () => secrets_1.default.createCredentials(profile, auth));
54
+ ? secrets_1.default.createCredentials(profile, auth, options)
55
+ : (0, jsonLib_1.getJSONAsync)(credentialsFile, () => secrets_1.default.createCredentials(profile, auth, options));
56
56
  }
57
57
  exports.getCredentials = getCredentials;
58
- async function createCredentials(profile, auth) {
59
- const scope = secrets_1.default.getScopes();
58
+ async function createCredentials(profile, auth, options) {
59
+ const scope = (options === null || options === void 0 ? void 0 : options.scopes) || secrets_1.default.getScopes();
60
60
  return new Promise((resolve) => {
61
61
  const authUrl = auth.generateAuthUrl({
62
62
  // eslint-disable-next-line camelcase
@@ -1 +1 @@
1
- {"version":3,"file":"secrets.js","sourceRoot":"","sources":["../../src/lib/secrets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,qDAAuC;AAGvC,uCAAkD;AAClD,qCAAuC;AACvC,mCAA4E;AAE5E,wDAAgC;AAGhC,kBAAe,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAE3H,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,WAAW,GAAI,oBAAoB,YAAY,gBAAgB,CAAC;AAEtE,SAAS,SAAS;IACjB,MAAM,UAAU,GAAG,IAAA,qBAAa,GAAE,CAAC;IACnC,MAAM,MAAM,GAAO,IAAA,iBAAO,EAAW,UAAU,EAAE,GAAG,EAAE,CAAC,IAAA,cAAK,EAAC,iBAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAU,CAAC,CAAC;IAC3G,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,OAAe;IAClC,MAAM,WAAW,GAAK,IAAA,sBAAc,EAAC,OAAO,CAAC,CAAC;IAC9C,MAAM,aAAa,GAAG,IAAA,iBAAO,EAAU,WAAW,EAAE,GAAG,EAAE,CAAC,IAAA,cAAK,EAAC,iBAAO,CAAC,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAU,CAAC,CAAC;IACzH,iBAAO,CAAC,YAAY,CAAC,OAAO,EAAE,aAAa,EAAE,WAAW,CAAC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B,yDAAyD;QACzD,iDAAiD;QACjD,qDAAqD;QACrD,2BAA2B;QAC3B,wBAAwB;QACxB,wCAAwC;QACxC,0GAA0G;QAC1G,mCAAmC;QACnC,oCAAoC;QACpC,uBAAuB,iBAAO,CAAC,SAAS,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACtD,mCAAmC;QACnC,yBAAyB;QACzB,wBAAwB;QACxB,mCAAmC;QACnC,oDAAoD;QACpD,6CAA6C;QAC7C,+DAA+D;QAC/D,mDAAmD;QACnD,yCAAyC;QACzC,wCAAwC,WAAW,EAAE;QACrD,wBAAwB;QACxB,uEAAuE,OAAO,OAAO;QACrF,8BAA8B;KAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC"}
@@ -11,4 +11,5 @@ export interface Secrets {
11
11
  }
12
12
  export interface AuthOptions {
13
13
  temporary?: boolean;
14
+ scopes?: string[];
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anmiles/google-api-wrapper",
3
- "version": "6.0.1",
3
+ "version": "6.1.0",
4
4
  "description": "Provides quick interface for getting google API data",
5
5
  "keywords": [
6
6
  "google",
@@ -202,7 +202,7 @@ describe('src/lib/secrets', () => {
202
202
  const fallback = getJSONAsyncSpy.mock.calls[0][1];
203
203
  await fallback();
204
204
 
205
- expect(secrets.createCredentials).toBeCalledWith(profile, auth);
205
+ expect(secrets.createCredentials).toBeCalledWith(profile, auth, undefined);
206
206
  });
207
207
 
208
208
  it('should call createCredentials directly if temporariness explicitly unset', async () => {
@@ -211,13 +211,13 @@ describe('src/lib/secrets', () => {
211
211
  const fallback = getJSONAsyncSpy.mock.calls[0][1];
212
212
  await fallback();
213
213
 
214
- expect(secrets.createCredentials).toBeCalledWith(profile, auth);
214
+ expect(secrets.createCredentials).toBeCalledWith(profile, auth, { temporary : false });
215
215
  });
216
216
 
217
217
  it('should call createCredentials directly if temporariness set', async () => {
218
218
  await original.getCredentials(profile, auth, { temporary : true });
219
219
 
220
- expect(secrets.createCredentials).toBeCalledWith(profile, auth);
220
+ expect(secrets.createCredentials).toBeCalledWith(profile, auth, { temporary : true });
221
221
  });
222
222
 
223
223
  it('should return credentials by default', async () => {
@@ -270,6 +270,18 @@ describe('src/lib/secrets', () => {
270
270
  });
271
271
  });
272
272
 
273
+ it('should generate authUrl with custom scopes', async () => {
274
+ willOpen(request, 100);
275
+
276
+ await original.createCredentials(profile, auth, { scopes : [ 'scope1', 'scope2' ] });
277
+
278
+ expect(auth.generateAuthUrl).toBeCalledWith({
279
+ // eslint-disable-next-line camelcase
280
+ access_type : 'offline',
281
+ scope : [ 'scope1', 'scope2' ],
282
+ });
283
+ });
284
+
273
285
  it('should create server on 6006 port', async () => {
274
286
  willOpen(request, 100);
275
287
 
@@ -287,6 +299,14 @@ describe('src/lib/secrets', () => {
287
299
  expect(logger.info).toBeCalledWith(`Please open yellow:https://authUrl in your browser using google profile for yellow:${profile} and allow access to yellow:https://www.googleapis.com/auth/calendar.calendars.readonly,https://www.googleapis.com/auth/calendar.events.readonly`);
288
300
  });
289
301
 
302
+ it('should ask to open browser page with custom scopes', async () => {
303
+ willOpen(request, 100);
304
+
305
+ await original.createCredentials(profile, auth, { scopes : [ 'scope1', 'scope2' ] });
306
+
307
+ expect(logger.info).toBeCalledWith(`Please open yellow:https://authUrl in your browser using google profile for yellow:${profile} and allow access to yellow:scope1,scope2`);
308
+ });
309
+
290
310
  it('should ask to close webpage', async () => {
291
311
  willOpen(request, 100);
292
312
 
@@ -31,12 +31,12 @@ async function getCredentials(profile: string, auth: GoogleApis.Common.OAuth2Cli
31
31
  const credentialsFile = getCredentialsFile(profile);
32
32
 
33
33
  return options?.temporary
34
- ? secrets.createCredentials(profile, auth)
35
- : getJSONAsync(credentialsFile, () => secrets.createCredentials(profile, auth));
34
+ ? secrets.createCredentials(profile, auth, options)
35
+ : getJSONAsync(credentialsFile, () => secrets.createCredentials(profile, auth, options));
36
36
  }
37
37
 
38
- async function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client): Promise<GoogleApis.Auth.Credentials> {
39
- const scope = secrets.getScopes();
38
+ async function createCredentials(profile: string, auth: GoogleApis.Auth.OAuth2Client, options?: AuthOptions): Promise<GoogleApis.Auth.Credentials> {
39
+ const scope = options?.scopes || secrets.getScopes();
40
40
 
41
41
  return new Promise((resolve) => {
42
42
  const authUrl = auth.generateAuthUrl({
@@ -11,6 +11,7 @@ export interface Secrets {
11
11
  }
12
12
 
13
13
  export interface AuthOptions {
14
- temporary?: boolean
14
+ temporary?: boolean;
15
+ scopes?: string[];
15
16
  }
16
17