powr-sdk-api 4.10.1 → 4.10.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.
@@ -10,9 +10,17 @@ const {
10
10
  config,
11
11
  credentials
12
12
  } = require('../config');
13
- const storage = new Storage({
14
- projectId: config.projectId,
15
- credentials: credentials
13
+ const gcpProject = process.env.GOOGLE_CLOUD_PROJECT_ID || process.env.GOOGLE_CLOUD_UPLOAD_PROJECT_ID || process.env.GCS_PROJECT_ID || process.env.GOOGLE_CLOUD_PROJECT;
14
+ const onCloudRun = Boolean(process.env.K_SERVICE);
15
+ const hasKeyFile = Boolean(credentials.client_email && credentials.private_key && credentials.private_key.includes('BEGIN PRIVATE KEY'));
16
+
17
+ // Cloud Run: use the runtime service account. JSON keys in .env often point
18
+ // at deleted SAs (invalid_grant: account not found).
19
+ const storage = new Storage(!onCloudRun && hasKeyFile ? {
20
+ projectId: gcpProject || credentials.project_id,
21
+ credentials
22
+ } : {
23
+ projectId: gcpProject
16
24
  });
17
25
  const bucketName = config.storageBucket;
18
26
  const bucket = storage.bucket(bucketName);
@@ -25,16 +33,12 @@ async function uploadToGCS(file) {
25
33
  const filename = `${timestamp}-${cleanFileName}`;
26
34
  const blob = bucket.file(filename);
27
35
  try {
28
- const buffer = file.buffer;
29
- await blob.save(buffer, {
36
+ await blob.save(file.buffer, {
30
37
  contentType: file.mimetype,
31
38
  metadata: {
32
39
  contentType: file.mimetype
33
40
  }
34
41
  });
35
-
36
- // Uniform bucket-level access rejects object ACLs. Public URL still works
37
- // if the bucket (or object) is already publicly readable.
38
42
  try {
39
43
  await blob.makePublic();
40
44
  } catch (aclError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-api",
3
- "version": "4.10.1",
3
+ "version": "4.10.2",
4
4
  "description": "Shared API core library for PowrStack projects. Zero dependencies - works with Express, Next.js API routes, and other frameworks. All features are optional and install only what you need.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",