@apolitical/server 4.3.0-pla-471.0 → 4.3.0-pla-471.2

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/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@apolitical/server",
3
- "version": "4.3.0-pla-471.0",
3
+ "version": "4.3.0-pla-471.2",
4
4
  "description": "Node.js module to encapsulate Apolitical's express server setup",
5
5
  "author": "Apolitical Group Limited <engineering@apolitical.co>",
6
6
  "license": "MIT",
7
7
  "main": "src/index.js",
8
8
  "exports": {
9
- ".": "./src/index.js",
10
- "./secrets": "./src/services/secret-manager.service.js"
9
+ ".": "./src/index.js"
11
10
  },
12
11
  "files": [
13
12
  "src"
package/src/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  'use strict';
2
2
 
3
3
  const { resolve } = require('./container');
4
+ const { SecretManagerService } = require('./services/secret-manager.service');
4
5
 
5
6
  // OTel must load before the Express server is started
6
7
  resolve('otelLoader')();
7
8
 
8
- module.exports = resolve('serverService');
9
+ const serverService = resolve('serverService');
10
+ serverService.SecretManagerService = SecretManagerService;
11
+
12
+ module.exports = serverService;
@@ -5,29 +5,30 @@ const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
5
5
  /**
6
6
  * Thin wrapper around Google Cloud Secret Manager.
7
7
  *
8
- * Every method is static because the class is consumed before the Awilix DI
9
- * container is available (e.g. inside app.js at startup).
8
+ * Every method is static because the class is consumed before the DI
9
+ * container is available (e.g. inside config loading at startup).
10
10
  * The underlying client is lazily created and reused across all calls.
11
+ *
12
+ * Ported from the backend/v2 implementation at:
13
+ * backend/v2/libs/externals/cloud/secrets/src/gcp-secret-manager.accessor.ts
11
14
  */
12
15
  class SecretManagerService {
13
16
  /**
14
17
  * Derive the secret name prefix from the PLATFORM_BASE_URL subdomain.
15
- * - https://apolitical.co -> "live"
16
- * - https://[beta|rc].apolitical.co -> "[beta|rc]"
17
- * - https://[beta|rc]-[e1|a1].apolitical.co -> "[beta|rc]"
18
- * - https://localhost -> "tilt" (Local Tilt)
19
- * - http://localhost -> "pnpm" (Local standalone)
18
+ * - https://apolitical.co "live"
19
+ * - https://[beta|rc].apolitical.co "[beta|rc]"
20
+ * - https://[beta|rc]-[e1|a1].apolitical.co "[beta|rc]"
21
+ * - https://localhost "tilt" (Local Tilt)
22
+ * - http://localhost "pnpm" (Local standalone)
20
23
  */
21
24
  static getSecretPrefix(useLocal) {
22
25
  const baseURL = String(process.env.PLATFORM_BASE_URL ?? '');
23
26
  try {
24
27
  const hostname = new URL(baseURL).hostname;
25
28
  if (hostname === 'apolitical.co') return 'live';
26
- if (hostname === 'localhost' && useLocal)
27
- return baseURL.startsWith('https') ? 'tilt' : 'pnpm';
29
+ if (hostname === 'localhost' && useLocal) return baseURL.startsWith('https') ? 'tilt' : 'pnpm';
28
30
  const parts = hostname.split('.');
29
- if (parts.length > 2 && hostname.endsWith('.apolitical.co'))
30
- return parts[0].replace(/-[a-z]\d+$/, '');
31
+ if (parts.length > 2 && hostname.endsWith('.apolitical.co')) return parts[0].replace(/-[a-z]\d+$/, '');
31
32
  } catch {
32
33
  /* fall through */
33
34
  }
@@ -37,7 +38,6 @@ class SecretManagerService {
37
38
  static async _getClient() {
38
39
  if (!this._clientPromise) {
39
40
  this._clientPromise = (async () => {
40
- // eslint-disable-next-line no-console
41
41
  console.log('[SecretManager] Initialising client.');
42
42
  return new SecretManagerServiceClient();
43
43
  })();
@@ -58,7 +58,6 @@ class SecretManagerService {
58
58
  const prefix = this.getSecretPrefix(options?.useLocal);
59
59
  const secretName = `${prefix}_${secretBaseName}`;
60
60
  const version = options?.version ?? 'latest';
61
-
62
61
  const name = `projects/${projectId}/secrets/${secretName}/versions/${version}`;
63
62
  const [response] = await client.accessSecretVersion({ name });
64
63