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

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
@@ -67,9 +67,8 @@ export class S3ModelConfig {
67
67
  /**
68
68
  * Provide host to bucket
69
69
  */
70
- get hostName(): string {
71
- return `${this.bucket}.s3.amazonaws.com`;
72
- }
70
+ @Required(false)
71
+ hostName: string;
73
72
 
74
73
  /**
75
74
  * Produces the s3 config from the provide details, post construction
@@ -81,6 +80,14 @@ export class S3ModelConfig {
81
80
  this.bucket ??= 'app';
82
81
  }
83
82
 
83
+ if (!this.hostName) {
84
+ if (this.endpoint && !this.endpoint.includes('localhost')) {
85
+ this.hostName = new URL(this.endpoint).host;
86
+ } else {
87
+ this.hostName = `${this.bucket}.s3.amazonaws.com`;
88
+ }
89
+ }
90
+
84
91
  if (!this.accessKeyId && !this.secretAccessKey) {
85
92
  const creds = await fromIni({ profile: this.profile })();
86
93
  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.18",
3
+ "version": "8.0.0-alpha.19",
4
4
  "type": "module",
5
5
  "description": "S3 backing for the travetto model module.",
6
6
  "keywords": [
@@ -30,10 +30,10 @@
30
30
  "@aws-sdk/credential-provider-ini": "^3.972.50",
31
31
  "@aws-sdk/s3-request-presigner": "^3.1063.0",
32
32
  "@travetto/config": "^8.0.0-alpha.18",
33
- "@travetto/model": "^8.0.0-alpha.18"
33
+ "@travetto/model": "^8.0.0-alpha.19"
34
34
  },
35
35
  "peerDependencies": {
36
- "@travetto/cli": "^8.0.0-alpha.23"
36
+ "@travetto/cli": "^8.0.0-alpha.24"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
package/src/config.ts CHANGED
@@ -35,9 +35,8 @@ export class S3ModelConfig {
35
35
  /**
36
36
  * Provide host to bucket
37
37
  */
38
- get hostName(): string {
39
- return `${this.bucket}.s3.amazonaws.com`;
40
- }
38
+ @Required(false)
39
+ hostName: string;
41
40
 
42
41
  /**
43
42
  * Produces the s3 config from the provide details, post construction
@@ -49,6 +48,14 @@ export class S3ModelConfig {
49
48
  this.bucket ??= 'app';
50
49
  }
51
50
 
51
+ if (!this.hostName) {
52
+ if (this.endpoint && !this.endpoint.includes('localhost')) {
53
+ this.hostName = new URL(this.endpoint).host;
54
+ } else {
55
+ this.hostName = `${this.bucket}.s3.amazonaws.com`;
56
+ }
57
+ }
58
+
52
59
  if (!this.accessKeyId && !this.secretAccessKey) {
53
60
  const creds = await fromIni({ profile: this.profile })();
54
61
  this.accessKeyId = creds.accessKeyId;
package/src/service.ts CHANGED
@@ -409,7 +409,17 @@ export class S3ModelService implements ModelCrudSupport, ModelBlobSupport, Model
409
409
  }
410
410
 
411
411
  // Signed urls
412
- async getBlobReadUrl(location: string, expiresIn: TimeSpan = '1h'): Promise<string> {
412
+ async getBlobReadUrl(location: string, expiresIn: TimeSpan | false = '1h'): Promise<string> {
413
+ if (expiresIn === false) {
414
+ const key = this.#basicKey(location);
415
+ const host = this.config.hostName;
416
+ const protocol = this.config.endpoint?.startsWith('http://') ? 'http' : 'https';
417
+ if (this.config.config.forcePathStyle) {
418
+ return `${protocol}://${host}/${this.config.bucket}/${key}`;
419
+ } else {
420
+ return `${protocol}://${host}/${key}`;
421
+ }
422
+ }
413
423
  return await getSignedUrl(
414
424
  this.client,
415
425
  new GetObjectCommand(this.#queryBlob(location)),