@sebspark/gcp-iam 1.0.0 → 1.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/dist/index.d.mts CHANGED
@@ -24,6 +24,6 @@ declare const clearCache: (key: string) => Promise<void>;
24
24
  * @param clientId OAUTH Client ID.
25
25
  * @returns ID Token.
26
26
  */
27
- declare const getApiGatewayTokenByClientId: (clientId: string) => Promise<string>;
27
+ declare const getApiGatewayTokenByClientId: (clientId: string, logger?: Logger) => Promise<string>;
28
28
 
29
29
  export { clearCache, getApiGatewayTokenByClientId, getApiGatewayTokenByUrl };
package/dist/index.d.ts CHANGED
@@ -24,6 +24,6 @@ declare const clearCache: (key: string) => Promise<void>;
24
24
  * @param clientId OAUTH Client ID.
25
25
  * @returns ID Token.
26
26
  */
27
- declare const getApiGatewayTokenByClientId: (clientId: string) => Promise<string>;
27
+ declare const getApiGatewayTokenByClientId: (clientId: string, logger?: Logger) => Promise<string>;
28
28
 
29
29
  export { clearCache, getApiGatewayTokenByClientId, getApiGatewayTokenByUrl };
package/dist/index.js CHANGED
@@ -125,7 +125,7 @@ var getApiGatewayTokenByUrl = async ({
125
125
  return signedJWT;
126
126
  } catch (error) {
127
127
  if (process.env.GCP_IAM_SOFT_FAIL === "true") {
128
- logger?.warn("Soft fail enabled, returning empty JWT");
128
+ logger?.info("Soft fail enabled, returning empty JWT");
129
129
  return "";
130
130
  }
131
131
  logger?.error("Error generating system JWT", error);
@@ -135,12 +135,21 @@ var getApiGatewayTokenByUrl = async ({
135
135
  var clearCache = async (key) => {
136
136
  apiGatewayJwtCache.clear(key);
137
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);
138
+ var getApiGatewayTokenByClientId = async (clientId, logger) => {
139
+ try {
140
+ const auth = new import_google_auth_library.GoogleAuth({
141
+ scopes: "https://www.googleapis.com/auth/cloud-platform"
142
+ });
143
+ const client = await auth.getIdTokenClient(clientId);
144
+ return await client.idTokenProvider.fetchIdToken(clientId);
145
+ } catch (error) {
146
+ if (process.env.GCP_IAM_SOFT_FAIL === "true") {
147
+ logger?.info("Soft fail enabled, returning empty JWT");
148
+ return "";
149
+ }
150
+ logger?.error("Error generating system JWT", error);
151
+ throw new Error(`Error generating system JWT: ${JSON.stringify(error)}`);
152
+ }
144
153
  };
145
154
  // Annotate the CommonJS export names for ESM import in node:
146
155
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -97,7 +97,7 @@ var getApiGatewayTokenByUrl = async ({
97
97
  return signedJWT;
98
98
  } catch (error) {
99
99
  if (process.env.GCP_IAM_SOFT_FAIL === "true") {
100
- logger?.warn("Soft fail enabled, returning empty JWT");
100
+ logger?.info("Soft fail enabled, returning empty JWT");
101
101
  return "";
102
102
  }
103
103
  logger?.error("Error generating system JWT", error);
@@ -107,12 +107,21 @@ var getApiGatewayTokenByUrl = async ({
107
107
  var clearCache = async (key) => {
108
108
  apiGatewayJwtCache.clear(key);
109
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);
110
+ var getApiGatewayTokenByClientId = async (clientId, logger) => {
111
+ try {
112
+ const auth = new GoogleAuth({
113
+ scopes: "https://www.googleapis.com/auth/cloud-platform"
114
+ });
115
+ const client = await auth.getIdTokenClient(clientId);
116
+ return await client.idTokenProvider.fetchIdToken(clientId);
117
+ } catch (error) {
118
+ if (process.env.GCP_IAM_SOFT_FAIL === "true") {
119
+ logger?.info("Soft fail enabled, returning empty JWT");
120
+ return "";
121
+ }
122
+ logger?.error("Error generating system JWT", error);
123
+ throw new Error(`Error generating system JWT: ${JSON.stringify(error)}`);
124
+ }
116
125
  };
117
126
  export {
118
127
  clearCache,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sebspark/gcp-iam",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",