@anmiles/google-api-wrapper 6.0.0 → 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 +8 -0
- package/dist/lib/api/shared.d.ts +6 -5
- package/dist/lib/api/shared.js.map +1 -1
- package/dist/lib/secrets.d.ts +1 -1
- package/dist/lib/secrets.js +4 -4
- package/dist/lib/secrets.js.map +1 -1
- package/dist/types/secrets.d.ts +1 -0
- package/package.json +1 -1
- package/src/lib/__tests__/secrets.test.ts +23 -3
- package/src/lib/api/shared.ts +4 -6
- package/src/lib/secrets.ts +4 -4
- package/src/types/secrets.ts +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,14 @@ 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
|
+
|
|
12
|
+
## [6.0.1](../../tags/v6.0.1) - 2023-03-20
|
|
13
|
+
### Changed
|
|
14
|
+
- Improved types for `getItems` method
|
|
15
|
+
|
|
8
16
|
## [6.0.0](../../tags/v6.0.0) - 2023-03-20
|
|
9
17
|
### Added
|
|
10
18
|
- Non-persistence mode for getAuth: ability to not save sensitive credentials into the file
|
package/dist/lib/api/shared.d.ts
CHANGED
|
@@ -6,11 +6,12 @@ declare const _default: {
|
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
|
8
8
|
type CommonApi<TItem> = {
|
|
9
|
-
list:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
9
|
+
list: {
|
|
10
|
+
(params?: {
|
|
11
|
+
pageToken: string | undefined;
|
|
12
|
+
}, options?: GoogleApis.Common.MethodOptions): Promise<GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>>>;
|
|
13
|
+
(callback: (err: Error | null, res?: GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>> | null) => void): void;
|
|
14
|
+
};
|
|
14
15
|
};
|
|
15
16
|
type CommonResponse<TItem> = {
|
|
16
17
|
items?: TItem[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;AAEA,sCAAgC;AAChC,oCAAiC;AAGjC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAE5B,MAAM,eAAe,GAAG,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/lib/api/shared.ts"],"names":[],"mappings":";;;AAEA,sCAAgC;AAChC,oCAAiC;AAGjC,kBAAe,EAAE,QAAQ,EAAE,CAAC;AAE5B,MAAM,eAAe,GAAG,GAAG,CAAC;AAiB5B,KAAK,UAAU,QAAQ,CAAQ,GAAqB,EAAE,MAAW,EAAE,OAAuB;;IACzF,MAAM,KAAK,GAAY,EAAE,CAAC;IAE1B,IAAI,SAAS,GAA8B,SAAS,CAAC;IAErD,GAAG;QACF,MAAM,QAAQ,GAA4D,MAAM,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QACnH,MAAA,QAAQ,CAAC,IAAI,CAAC,KAAK,0CAAE,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAEzD,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,CAAA,EAAE;YAC3B,IAAA,YAAG,EAAC,kBAAkB,KAAK,CAAC,MAAM,OAAO,CAAA,MAAA,QAAQ,CAAC,IAAI,CAAC,QAAQ,0CAAE,YAAY,KAAI,MAAM,MAAM,CAAC,CAAC;SAC/F;QAED,MAAM,IAAA,aAAK,EAAC,eAAe,CAAC,CAAC;QAC7B,SAAS,GAAG,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC;KACxC,QAAQ,SAAS,EAAE;IAEpB,OAAO,KAAK,CAAC;AACd,CAAC;AAtCQ,4BAAQ"}
|
package/dist/lib/secrets.d.ts
CHANGED
|
@@ -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;
|
package/dist/lib/secrets.js
CHANGED
|
@@ -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
|
package/dist/lib/secrets.js.map
CHANGED
|
@@ -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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tC,0BAA0B;QAC1B,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"}
|
package/dist/types/secrets.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -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
|
|
package/src/lib/api/shared.ts
CHANGED
|
@@ -9,12 +9,10 @@ export default { getItems };
|
|
|
9
9
|
const requestInterval = 300;
|
|
10
10
|
|
|
11
11
|
type CommonApi<TItem> = {
|
|
12
|
-
list:
|
|
13
|
-
params?: { pageToken: string | undefined },
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} & {
|
|
17
|
-
list: (callback: (err: Error | null, res?: GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>> | null) => void) => void
|
|
12
|
+
list: {
|
|
13
|
+
(params?: { pageToken: string | undefined }, options?: GoogleApis.Common.MethodOptions): Promise<GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>>>;
|
|
14
|
+
(callback: (err: Error | null, res?: GoogleApis.Common.GaxiosResponse<CommonResponse<TItem>> | null) => void): void;
|
|
15
|
+
}
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
type CommonResponse<TItem> = {
|
package/src/lib/secrets.ts
CHANGED
|
@@ -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({
|