@sebspark/gcp-iam 0.4.1 → 1.0.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/dist/index.d.mts CHANGED
@@ -8,11 +8,22 @@ import { Logger } from 'winston';
8
8
  * @param logger An optional logger to use for logging.
9
9
  * @returns A JWT.
10
10
  */
11
- declare const getApiGatewayToken: ({ apiURL, key, ttl, logger, }: {
11
+ declare const getApiGatewayTokenByUrl: ({ apiURL, key, ttl, logger, }: {
12
12
  apiURL: string;
13
13
  key?: string;
14
14
  ttl?: number;
15
15
  logger?: Logger;
16
16
  }) => Promise<string>;
17
+ /**
18
+ *
19
+ * @param key Clears a cached JWT by key.
20
+ */
21
+ declare const clearCache: (key: string) => Promise<void>;
22
+ /**
23
+ * Generates a JWT for the API Gateway, using Client ID as audience.
24
+ * @param clientId OAUTH Client ID.
25
+ * @returns ID Token.
26
+ */
27
+ declare const getApiGatewayTokenByClientId: (clientId: string) => Promise<string>;
17
28
 
18
- export { getApiGatewayToken };
29
+ export { clearCache, getApiGatewayTokenByClientId, getApiGatewayTokenByUrl };
package/dist/index.d.ts CHANGED
@@ -8,11 +8,22 @@ import { Logger } from 'winston';
8
8
  * @param logger An optional logger to use for logging.
9
9
  * @returns A JWT.
10
10
  */
11
- declare const getApiGatewayToken: ({ apiURL, key, ttl, logger, }: {
11
+ declare const getApiGatewayTokenByUrl: ({ apiURL, key, ttl, logger, }: {
12
12
  apiURL: string;
13
13
  key?: string;
14
14
  ttl?: number;
15
15
  logger?: Logger;
16
16
  }) => Promise<string>;
17
+ /**
18
+ *
19
+ * @param key Clears a cached JWT by key.
20
+ */
21
+ declare const clearCache: (key: string) => Promise<void>;
22
+ /**
23
+ * Generates a JWT for the API Gateway, using Client ID as audience.
24
+ * @param clientId OAUTH Client ID.
25
+ * @returns ID Token.
26
+ */
27
+ declare const getApiGatewayTokenByClientId: (clientId: string) => Promise<string>;
17
28
 
18
- export { getApiGatewayToken };
29
+ export { clearCache, getApiGatewayTokenByClientId, getApiGatewayTokenByUrl };
package/dist/index.js CHANGED
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- getApiGatewayToken: () => getApiGatewayToken
23
+ clearCache: () => clearCache,
24
+ getApiGatewayTokenByClientId: () => getApiGatewayTokenByClientId,
25
+ getApiGatewayTokenByUrl: () => getApiGatewayTokenByUrl
24
26
  });
25
27
  module.exports = __toCommonJS(index_exports);
26
28
 
@@ -62,12 +64,15 @@ var LruCache = class {
62
64
  ttl: ttl || this.defaultTTL
63
65
  });
64
66
  }
67
+ clear(key) {
68
+ this.values.delete(key);
69
+ }
65
70
  };
66
71
 
67
72
  // src/apiGatewayToken.ts
68
73
  var expInSeconds = 60 * 60;
69
74
  var apiGatewayJwtCache = new LruCache();
70
- var getApiGatewayToken = async ({
75
+ var getApiGatewayTokenByUrl = async ({
71
76
  apiURL,
72
77
  key,
73
78
  ttl,
@@ -127,7 +132,19 @@ var getApiGatewayToken = async ({
127
132
  throw new Error(`Error generating system JWT: ${JSON.stringify(error)}`);
128
133
  }
129
134
  };
135
+ var clearCache = async (key) => {
136
+ apiGatewayJwtCache.clear(key);
137
+ };
138
+ var getApiGatewayTokenByClientId = async (clientId) => {
139
+ const auth = new import_google_auth_library.GoogleAuth({
140
+ scopes: "https://www.googleapis.com/auth/cloud-platform"
141
+ });
142
+ const client = await auth.getIdTokenClient(clientId);
143
+ return await client.idTokenProvider.fetchIdToken(clientId);
144
+ };
130
145
  // Annotate the CommonJS export names for ESM import in node:
131
146
  0 && (module.exports = {
132
- getApiGatewayToken
147
+ clearCache,
148
+ getApiGatewayTokenByClientId,
149
+ getApiGatewayTokenByUrl
133
150
  });
package/dist/index.mjs CHANGED
@@ -36,12 +36,15 @@ var LruCache = class {
36
36
  ttl: ttl || this.defaultTTL
37
37
  });
38
38
  }
39
+ clear(key) {
40
+ this.values.delete(key);
41
+ }
39
42
  };
40
43
 
41
44
  // src/apiGatewayToken.ts
42
45
  var expInSeconds = 60 * 60;
43
46
  var apiGatewayJwtCache = new LruCache();
44
- var getApiGatewayToken = async ({
47
+ var getApiGatewayTokenByUrl = async ({
45
48
  apiURL,
46
49
  key,
47
50
  ttl,
@@ -101,6 +104,18 @@ var getApiGatewayToken = async ({
101
104
  throw new Error(`Error generating system JWT: ${JSON.stringify(error)}`);
102
105
  }
103
106
  };
107
+ var clearCache = async (key) => {
108
+ apiGatewayJwtCache.clear(key);
109
+ };
110
+ var getApiGatewayTokenByClientId = async (clientId) => {
111
+ const auth = new GoogleAuth({
112
+ scopes: "https://www.googleapis.com/auth/cloud-platform"
113
+ });
114
+ const client = await auth.getIdTokenClient(clientId);
115
+ return await client.idTokenProvider.fetchIdToken(clientId);
116
+ };
104
117
  export {
105
- getApiGatewayToken
118
+ clearCache,
119
+ getApiGatewayTokenByClientId,
120
+ getApiGatewayTokenByUrl
106
121
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/gcp-iam",
3
- "version": "0.4.1",
3
+ "version": "1.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",