Given the third party library here, @google-cloud/secret-manager
might not support ESM as of now, probably found a way around to the __dirname
issue by making use of google-api-nodejs-client which is a wrapper over the Google REST APIs. Given this library has full typescript support, we can utilize the it to perform the same functionality of fetching secret value. The function mentioned above to fetch the secret value can be refactored in the given snippet:
...
// import { v1 } from '@google-cloud/secret-manager'; -- removed
import { google } from 'googleapis';
...
...
// const secretManagerClient = new v1.SecretManagerServiceClient(); -- removed
async function fetchSecretByName(secretName: string): Promise<string | undefined> { // refactored
const auth = new google.auth.GoogleAuth();
// obtain the current project Id
const project = await auth.getProjectId();
// build secret manager client
const secretManager = google.secretmanager({ auth: auth, version: 'v1' });
// fetch the secret value
const res = await secretManager.projects.secrets.versions.access({
name: secretName,
})
return Buffer.from(res.data.payload?.data?.toString() as string, 'base64').toString('utf8');
}
This helped overcome the issue of google-gax
used in google-cloud-node library. Hope this comes in help to someone facing a similar issue of google-cloud-node
in Angular 19 SSR.