@travetto/model-s3 8.0.0-alpha.19 → 8.0.0-alpha.20

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
@@ -65,10 +65,10 @@ export class S3ModelConfig {
65
65
  modifyStorage?: boolean;
66
66
 
67
67
  /**
68
- * Provide host to bucket
68
+ * Provide base URL for public access
69
69
  */
70
70
  @Required(false)
71
- hostName: string;
71
+ publicBaseUrl: string;
72
72
 
73
73
  /**
74
74
  * Produces the s3 config from the provide details, post construction
@@ -80,14 +80,26 @@ export class S3ModelConfig {
80
80
  this.bucket ??= 'app';
81
81
  }
82
82
 
83
- if (!this.hostName) {
84
- if (this.endpoint && !this.endpoint.includes('localhost')) {
85
- this.hostName = new URL(this.endpoint).host;
83
+ if (!this.publicBaseUrl) {
84
+ if (this.endpoint) {
85
+ if (this.endpoint.includes('localhost')) {
86
+ this.publicBaseUrl = this.endpoint;
87
+ } else {
88
+ try {
89
+ this.publicBaseUrl = new URL(this.endpoint).origin;
90
+ } catch {
91
+ this.publicBaseUrl = this.endpoint;
92
+ }
93
+ }
86
94
  } else {
87
- this.hostName = `${this.bucket}.s3.amazonaws.com`;
95
+ this.publicBaseUrl = `https://${this.bucket}.s3.amazonaws.com`;
88
96
  }
89
97
  }
90
98
 
99
+ if (this.publicBaseUrl && !this.publicBaseUrl.includes('://')) {
100
+ this.publicBaseUrl = `https://${this.publicBaseUrl}`;
101
+ }
102
+
91
103
  if (!this.accessKeyId && !this.secretAccessKey) {
92
104
  const creds = await fromIni({ profile: this.profile })();
93
105
  this.accessKeyId = creds.accessKeyId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-s3",
3
- "version": "8.0.0-alpha.19",
3
+ "version": "8.0.0-alpha.20",
4
4
  "type": "module",
5
5
  "description": "S3 backing for the travetto model module.",
6
6
  "keywords": [
@@ -29,11 +29,11 @@
29
29
  "@aws-sdk/client-s3": "^3.1063.0",
30
30
  "@aws-sdk/credential-provider-ini": "^3.972.50",
31
31
  "@aws-sdk/s3-request-presigner": "^3.1063.0",
32
- "@travetto/config": "^8.0.0-alpha.18",
33
- "@travetto/model": "^8.0.0-alpha.19"
32
+ "@travetto/config": "^8.0.0-alpha.19",
33
+ "@travetto/model": "^8.0.0-alpha.20"
34
34
  },
35
35
  "peerDependencies": {
36
- "@travetto/cli": "^8.0.0-alpha.24"
36
+ "@travetto/cli": "^8.0.0-alpha.25"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
package/src/config.ts CHANGED
@@ -2,7 +2,7 @@ import { fromIni } from '@aws-sdk/credential-provider-ini';
2
2
  import type s3 from '@aws-sdk/client-s3';
3
3
 
4
4
  import { Config, EnvVar } from '@travetto/config';
5
- import { Required } from '@travetto/schema';
5
+ import { Required, Url } from '@travetto/schema';
6
6
  import { Runtime } from '@travetto/runtime';
7
7
  import { PostConstruct } from '@travetto/di';
8
8
 
@@ -33,10 +33,11 @@ export class S3ModelConfig {
33
33
  modifyStorage?: boolean;
34
34
 
35
35
  /**
36
- * Provide host to bucket
36
+ * Provide base URL for public access
37
37
  */
38
+ @Url()
38
39
  @Required(false)
39
- hostName: string;
40
+ publicBaseUrl: string;
40
41
 
41
42
  /**
42
43
  * Produces the s3 config from the provide details, post construction
@@ -48,11 +49,11 @@ export class S3ModelConfig {
48
49
  this.bucket ??= 'app';
49
50
  }
50
51
 
51
- if (!this.hostName) {
52
- if (this.endpoint && !this.endpoint.includes('localhost')) {
53
- this.hostName = new URL(this.endpoint).host;
52
+ if (!this.publicBaseUrl) {
53
+ if (this.endpoint?.includes('localhost')) {
54
+ this.publicBaseUrl = this.endpoint;
54
55
  } else {
55
- this.hostName = `${this.bucket}.s3.amazonaws.com`;
56
+ this.publicBaseUrl = `https://${this.bucket}.s3.amazonaws.com`;
56
57
  }
57
58
  }
58
59
 
package/src/service.ts CHANGED
@@ -412,12 +412,11 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
412
412
  async getBlobReadUrl(location: string, expiresIn: TimeSpan | false = '1h'): Promise<string> {
413
413
  if (expiresIn === false) {
414
414
  const key = this.#basicKey(location);
415
- const host = this.config.hostName;
416
- const protocol = this.config.endpoint?.startsWith('http://') ? 'http' : 'https';
415
+ const baseUrl = this.config.publicBaseUrl;
417
416
  if (this.config.config.forcePathStyle) {
418
- return `${protocol}://${host}/${this.config.bucket}/${key}`;
417
+ return `${baseUrl}/${this.config.bucket}/${key}`;
419
418
  } else {
420
- return `${protocol}://${host}/${key}`;
419
+ return `${baseUrl}/${key}`;
421
420
  }
422
421
  }
423
422
  return await getSignedUrl(