@travetto/model-s3 8.0.1 → 8.0.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/README.md CHANGED
@@ -81,32 +81,28 @@ export class S3ModelConfig {
81
81
  this.bucket ??= 'app';
82
82
  }
83
83
 
84
- if (!this.publicBaseUrl) {
85
- if (this.endpoint?.includes('localhost')) {
86
- this.publicBaseUrl = this.endpoint;
87
- } else {
88
- this.publicBaseUrl = `https://${this.bucket}.s3.amazonaws.com`;
89
- }
90
- }
91
-
92
84
  if (!this.accessKeyId && !this.secretAccessKey) {
93
85
  const credentials = await fromIni({ profile: this.profile })();
94
86
  this.accessKeyId = credentials.accessKeyId;
95
87
  this.secretAccessKey = credentials.secretAccessKey;
96
88
  }
97
89
 
90
+ const hostname = this.endpoint && URL.canParse(this.endpoint) ? new URL(this.endpoint).hostname : '';
91
+ const isAws = !this.endpoint || hostname === 'amazonaws.com' || hostname.endsWith('.amazonaws.com');
92
+
98
93
  this.config = {
99
94
  ...(this.config ?? {}),
100
95
  region: this.region,
101
- endpoint: this.endpoint,
96
+ endpoint: this.endpoint || undefined,
97
+ forcePathStyle: this.config?.forcePathStyle ?? !isAws,
102
98
  credentials: {
103
99
  accessKeyId: this.accessKeyId,
104
100
  secretAccessKey: this.secretAccessKey
105
101
  }
106
102
  };
107
103
 
108
- if (!Runtime.production && this.endpoint.includes('localhost')) {
109
- this.config.forcePathStyle ??= true;
104
+ if (!this.publicBaseUrl) {
105
+ this.publicBaseUrl = isAws ? `https://${this.bucket}.s3.amazonaws.com` : `${this.endpoint.replace(/\/+$/, '')}/${this.bucket}`;
110
106
  }
111
107
  }
112
108
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-s3",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "S3 backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "model",
package/src/config.ts CHANGED
@@ -49,32 +49,28 @@ export class S3ModelConfig {
49
49
  this.bucket ??= 'app';
50
50
  }
51
51
 
52
- if (!this.publicBaseUrl) {
53
- if (this.endpoint?.includes('localhost')) {
54
- this.publicBaseUrl = this.endpoint;
55
- } else {
56
- this.publicBaseUrl = `https://${this.bucket}.s3.amazonaws.com`;
57
- }
58
- }
59
-
60
52
  if (!this.accessKeyId && !this.secretAccessKey) {
61
53
  const credentials = await fromIni({ profile: this.profile })();
62
54
  this.accessKeyId = credentials.accessKeyId;
63
55
  this.secretAccessKey = credentials.secretAccessKey;
64
56
  }
65
57
 
58
+ const hostname = this.endpoint && URL.canParse(this.endpoint) ? new URL(this.endpoint).hostname : '';
59
+ const isAws = !this.endpoint || hostname === 'amazonaws.com' || hostname.endsWith('.amazonaws.com');
60
+
66
61
  this.config = {
67
62
  ...(this.config ?? {}),
68
63
  region: this.region,
69
- endpoint: this.endpoint,
64
+ endpoint: this.endpoint || undefined,
65
+ forcePathStyle: this.config?.forcePathStyle ?? !isAws,
70
66
  credentials: {
71
67
  accessKeyId: this.accessKeyId,
72
68
  secretAccessKey: this.secretAccessKey
73
69
  }
74
70
  };
75
71
 
76
- if (!Runtime.production && this.endpoint.includes('localhost')) {
77
- this.config.forcePathStyle ??= true;
72
+ if (!this.publicBaseUrl) {
73
+ this.publicBaseUrl = isAws ? `https://${this.bucket}.s3.amazonaws.com` : `${this.endpoint.replace(/\/+$/, '')}/${this.bucket}`;
78
74
  }
79
75
  }
80
76
  }
package/src/service.ts CHANGED
@@ -459,12 +459,7 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
459
459
  async getBlobReadUrl(location: string, expiresIn: TimeSpan | false = '1h'): Promise<string> {
460
460
  if (expiresIn === false) {
461
461
  const key = this.#basicKey(location);
462
- const baseUrl = this.config.publicBaseUrl;
463
- if (this.config.config.forcePathStyle) {
464
- return `${baseUrl}/${this.config.bucket}/${key}`;
465
- } else {
466
- return `${baseUrl}/${key}`;
467
- }
462
+ return `${this.config.publicBaseUrl}/${key}`;
468
463
  }
469
464
  return await getSignedUrl(this.client, new GetObjectCommand(this.#queryBlob(location)), {
470
465
  expiresIn: TimeUtil.duration(expiresIn, 's')