@nextlyhq/storage-s3 0.0.2-alpha.73 → 0.0.2-alpha.75

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/dist/index.d.cts CHANGED
@@ -553,8 +553,8 @@ interface ResolvedS3Config {
553
553
  * @param config - S3 storage configuration
554
554
  * @returns A StoragePlugin that MediaStorage can register
555
555
  *
556
- * @throws Error if bucket is not provided (via adapter)
557
- * @throws Error if region is not provided (via adapter)
556
+ * Constructing the plugin never requires the bucket or region: a missing
557
+ * one is refused when storage is first used, not while the config loads.
558
558
  */
559
559
  export declare function s3Storage(config: S3StorageConfig): StoragePlugin;
560
560
  export declare class S3StorageAdapter implements IStorageAdapter {
@@ -565,10 +565,38 @@ export declare class S3StorageAdapter implements IStorageAdapter {
565
565
  /**
566
566
  * Create a new S3 storage adapter.
567
567
  *
568
+ * The bucket and region are deliberately NOT checked here, and the SDK
569
+ * client is deliberately not built. This constructor runs while the host's
570
+ * config file is evaluated, so a throw would stop every command —
571
+ * including the schema-only ones that never touch storage. Both the checks
572
+ * and the client construction move to the first storage operation
573
+ * ({@link ensureClient} and {@link ensureConfigured}), which refuse with
574
+ * the same messages a missing bucket or region has always produced.
575
+ *
568
576
  * @param config - S3 storage configuration
569
- * @throws Error if bucket or region is not provided
570
577
  */
571
578
  constructor(config: S3StorageConfig);
579
+ /**
580
+ * Validate that bucket and region are present.
581
+ *
582
+ * @throws Error if bucket is not provided
583
+ * @throws Error if region is not provided
584
+ */
585
+ private ensureConfigured;
586
+ /**
587
+ * Validate the stored configuration and build the SDK client, at the
588
+ * first use that needs them.
589
+ *
590
+ * The refusals are the ones the constructor used to throw, in the same
591
+ * order, so an operator with a genuinely misconfigured deployment sees
592
+ * the message they have always seen — at the moment the value was
593
+ * actually needed rather than at config load. The client is built once
594
+ * and reused.
595
+ *
596
+ * @throws Error if bucket is not provided
597
+ * @throws Error if region is not provided
598
+ */
599
+ private ensureClient;
572
600
  /**
573
601
  * Build AWS credentials from config.
574
602
  * Supports explicit credentials or falls back to SDK default chain.
@@ -764,6 +792,10 @@ export declare class S3StorageAdapter implements IStorageAdapter {
764
792
  /**
765
793
  * Get the S3 client instance.
766
794
  * Useful for advanced operations not covered by the adapter interface.
795
+ *
796
+ * Handing out the client is itself a use of the adapter, so a caller
797
+ * without the configuration a client needs is refused here like any
798
+ * other operation.
767
799
  */
768
800
  getClient(): S3Client;
769
801
  /**
package/dist/index.d.ts CHANGED
@@ -553,8 +553,8 @@ interface ResolvedS3Config {
553
553
  * @param config - S3 storage configuration
554
554
  * @returns A StoragePlugin that MediaStorage can register
555
555
  *
556
- * @throws Error if bucket is not provided (via adapter)
557
- * @throws Error if region is not provided (via adapter)
556
+ * Constructing the plugin never requires the bucket or region: a missing
557
+ * one is refused when storage is first used, not while the config loads.
558
558
  */
559
559
  export declare function s3Storage(config: S3StorageConfig): StoragePlugin;
560
560
  export declare class S3StorageAdapter implements IStorageAdapter {
@@ -565,10 +565,38 @@ export declare class S3StorageAdapter implements IStorageAdapter {
565
565
  /**
566
566
  * Create a new S3 storage adapter.
567
567
  *
568
+ * The bucket and region are deliberately NOT checked here, and the SDK
569
+ * client is deliberately not built. This constructor runs while the host's
570
+ * config file is evaluated, so a throw would stop every command —
571
+ * including the schema-only ones that never touch storage. Both the checks
572
+ * and the client construction move to the first storage operation
573
+ * ({@link ensureClient} and {@link ensureConfigured}), which refuse with
574
+ * the same messages a missing bucket or region has always produced.
575
+ *
568
576
  * @param config - S3 storage configuration
569
- * @throws Error if bucket or region is not provided
570
577
  */
571
578
  constructor(config: S3StorageConfig);
579
+ /**
580
+ * Validate that bucket and region are present.
581
+ *
582
+ * @throws Error if bucket is not provided
583
+ * @throws Error if region is not provided
584
+ */
585
+ private ensureConfigured;
586
+ /**
587
+ * Validate the stored configuration and build the SDK client, at the
588
+ * first use that needs them.
589
+ *
590
+ * The refusals are the ones the constructor used to throw, in the same
591
+ * order, so an operator with a genuinely misconfigured deployment sees
592
+ * the message they have always seen — at the moment the value was
593
+ * actually needed rather than at config load. The client is built once
594
+ * and reused.
595
+ *
596
+ * @throws Error if bucket is not provided
597
+ * @throws Error if region is not provided
598
+ */
599
+ private ensureClient;
572
600
  /**
573
601
  * Build AWS credentials from config.
574
602
  * Supports explicit credentials or falls back to SDK default chain.
@@ -764,6 +792,10 @@ export declare class S3StorageAdapter implements IStorageAdapter {
764
792
  /**
765
793
  * Get the S3 client instance.
766
794
  * Useful for advanced operations not covered by the adapter interface.
795
+ *
796
+ * Handing out the client is itself a use of the adapter, so a caller
797
+ * without the configuration a client needs is refused here like any
798
+ * other operation.
767
799
  */
768
800
  getClient(): S3Client;
769
801
  /**
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DeleteObjectCommand, DeleteObjectsCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
2
2
  import { Upload } from "@aws-sdk/lib-storage";
3
3
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
4
- // ../nextly/dist/nextly-error-BLaA7N-v.mjs
4
+ // ../nextly/dist/nextly-error-BElDQWyI.mjs
5
5
  function isDbError(err) {
6
6
  if (!err || typeof err !== "object") return false;
7
7
  const obj = err;
@@ -77,12 +77,15 @@ const NEXTLY_ERROR_STATUS = {
77
77
  CSRF_FAILED: 403,
78
78
  SETUP_TOKEN_REQUIRED: 403,
79
79
  API_KEY_ROLE_ABOVE_CREATOR: 403,
80
+ ACTION_NOT_AVAILABLE: 403,
80
81
  NOT_FOUND: 404,
81
82
  ENTITY_REMOVED_FROM_CODE: 409,
82
83
  ENTITY_NOT_MIGRATED: 409,
83
84
  METHOD_NOT_ALLOWED: 405,
84
85
  RANGE_NOT_SATISFIABLE: 416,
85
86
  CONFLICT: 409,
87
+ STALE_VERSION: 409,
88
+ VERSION_REQUIRED: 428,
86
89
  DUPLICATE: 409,
87
90
  RATE_LIMITED: 429,
88
91
  PAYLOAD_TOO_LARGE: 413,
@@ -91,6 +94,7 @@ const NEXTLY_ERROR_STATUS = {
91
94
  INTERNAL_ERROR: 500,
92
95
  DATABASE_ERROR: 500,
93
96
  DATABASE_BUSY: 503,
97
+ RULE_COULD_NOT_RUN: 503,
94
98
  EXTERNAL_SERVICE_ERROR: 502,
95
99
  SERVICE_UNAVAILABLE: 503,
96
100
  CONFIGURATION_ERROR: 500,
@@ -125,6 +129,8 @@ const NEXTLY_ERROR_STATUS = {
125
129
  NEXTLY_MIGRATION_SNAPSHOT_MISSING: 404,
126
130
  NEXTLY_MIGRATION_RESOLVE_DRIFT: 409,
127
131
  NEXTLY_MIGRATION_RESOLVE_PRECONDITION: 409,
132
+ NEXTLY_MIGRATION_HISTORY_REFUSED: 409,
133
+ NEXTLY_SCHEMA_CONVERSION_UNCONFIRMED: 409,
128
134
  NEXTLY_UI_SCHEMA_INVALID: 400,
129
135
  NEXTLY_SCHEMA_SLUG_COLLISION: 409,
130
136
  NEXTLY_SCHEMA_RELATION_TARGET_MISSING: 400,
@@ -137,9 +143,11 @@ const NEXTLY_ERROR_STATUS = {
137
143
  NEXTLY_PLUGIN_ADMIN_WIDGET_INVALID: 500,
138
144
  NEXTLY_PLUGIN_REMOVED_WIDGET_CHANNEL: 500,
139
145
  NEXTLY_PLUGIN_DOCUMENT_VIEW_INVALID: 500,
146
+ NEXTLY_PLUGIN_DOCUMENT_SURFACE_INVALID: 500,
140
147
  PLUGIN_RESOLUTION_ERROR: 500,
141
148
  PLUGIN_DEPENDENCY_NOT_INSTALLED: 409,
142
149
  PLUGIN_HAS_DEPENDENTS: 409,
150
+ PLUGIN_UNINSTALL_WOULD_DROP_OTHERS: 409,
143
151
  PLUGIN_UNINSTALL_IRREVERSIBLE: 409,
144
152
  PLUGIN_UNINSTALL_UNCONFIRMED: 409,
145
153
  PLUGIN_SCHEMA_BEHIND: 409,
@@ -163,6 +171,9 @@ const NEXTLY_ERROR_STATUS = {
163
171
  NEXTLY_EMAIL_TRANSPORT_UNAVAILABLE: 503,
164
172
  NEXTLY_CONFIG_TOOLING_UNAVAILABLE: 503,
165
173
  NEXTLY_POSTGRES_SCHEMA_MISMATCH: 500,
174
+ NEXTLY_PER_LANGUAGE_STORAGE_CHANGED: 500,
175
+ NEXTLY_PER_LANGUAGE_STORAGE_MIXED: 500,
176
+ NEXTLY_PER_LANGUAGE_STORAGE_LANGUAGES_UNDECLARED: 500,
166
177
  NEXTLY_POSTGRES_SCHEMA_UNSUPPORTED: 500
167
178
  };
168
179
  ({ ...Object.fromEntries([
@@ -171,6 +182,7 @@ const NEXTLY_ERROR_STATUS = {
171
182
  "FORBIDDEN",
172
183
  "NOT_FOUND",
173
184
  "CONFLICT",
185
+ "VERSION_REQUIRED",
174
186
  "PAYLOAD_TOO_LARGE",
175
187
  "UNSUPPORTED_MEDIA_TYPE",
176
188
  "RATE_LIMITED",
@@ -194,6 +206,7 @@ const GENERIC_PUBLIC_MESSAGE = {
194
206
  INVALID_INPUT: "The request could not be processed.",
195
207
  AUTH_REQUIRED: "Authentication required.",
196
208
  FORBIDDEN: "You don't have permission to perform this action.",
209
+ ACTION_NOT_AVAILABLE: "This action isn't available for this entry.",
197
210
  NOT_FOUND: "Not found.",
198
211
  METHOD_NOT_ALLOWED: "That method is not allowed on this address.",
199
212
  RANGE_NOT_SATISFIABLE: "The requested range is outside the file.",
@@ -205,6 +218,7 @@ const GENERIC_PUBLIC_MESSAGE = {
205
218
  EXTERNAL_SERVICE_ERROR: "An upstream service failed.",
206
219
  SERVICE_UNAVAILABLE: "The service is temporarily unavailable.",
207
220
  DATABASE_BUSY: "The database is busy. Please try again shortly.",
221
+ RULE_COULD_NOT_RUN: "A check this request needs could not run. Please try again shortly.",
208
222
  INTERNAL_ERROR: "An unexpected error occurred."
209
223
  };
210
224
  /** The generic sentence for a code; the internal one for anything unlisted. */
@@ -412,6 +426,7 @@ var NextlyError = class NextlyError extends Error {
412
426
  return new NextlyError({
413
427
  code: "FORBIDDEN",
414
428
  publicMessage: "You don't have permission to perform this action.",
429
+ publicData: opts?.publicData,
415
430
  cause: opts?.cause,
416
431
  logContext: opts?.logContext
417
432
  });
@@ -613,10 +628,69 @@ var NextlyError = class NextlyError extends Error {
613
628
  }
614
629
  });
615
630
  }
631
+ /**
632
+ * An update made from a version of the document that is no longer its
633
+ * current one. Never retried: the same version stays out of date, so the
634
+ * caller must read the document again and decide.
635
+ *
636
+ * @experimental
637
+ */
638
+ /**
639
+ * An update that said neither which version of a document it was made from
640
+ * nor that it overwrites whatever is stored. Without `bulk`, an update of
641
+ * one document, which sends back the version it read. `bulk` names an
642
+ * update that writes the same values to many documents, which can carry no
643
+ * one document's version: by its ids, which can be given a version each
644
+ * (`keys.revs`), or by a query, which cannot. The keys are the write path's
645
+ * to name, so the message spells them as the request does.
646
+ *
647
+ * @experimental
648
+ */
649
+ static versionRequired(opts) {
650
+ const { version, overwrite, revs } = opts.keys;
651
+ if (opts.bulk === void 0) {
652
+ const one = {
653
+ versionKey: version,
654
+ overwriteKey: overwrite
655
+ };
656
+ return new NextlyError({
657
+ code: "VERSION_REQUIRED",
658
+ publicMessage: `This update must say which version of the document it changes. Send back the \`${version}\` from your last read of it, or set \`${overwrite}: true\` to replace whatever is stored.`,
659
+ publicData: one,
660
+ logContext: opts.logContext
661
+ });
662
+ }
663
+ const byIds = opts.bulk === "ids";
664
+ const data = {
665
+ versionKey: version,
666
+ overwriteKey: overwrite,
667
+ ...byIds ? { revsKey: revs } : {}
668
+ };
669
+ const message = `An update that writes the same values to many documents must set \`${overwrite}: true\`: it can't carry each document's version. Or update each document with its own \`${version}\`.`;
670
+ return new NextlyError({
671
+ code: "VERSION_REQUIRED",
672
+ publicMessage: byIds ? `${message} Or give each document's \`${version}\` in \`${revs}\`.` : message,
673
+ publicData: data,
674
+ logContext: opts.logContext
675
+ });
676
+ }
677
+ static staleVersion(opts) {
678
+ return new NextlyError({
679
+ code: "STALE_VERSION",
680
+ publicMessage: `This document changed since the version you gave. Its current version is ${opts.data.currentVersion}.`,
681
+ publicData: opts.data,
682
+ logContext: opts.logContext
683
+ });
684
+ }
685
+ /**
686
+ * `message` replaces the generic sentence where the caller can name what is
687
+ * already taken without leaking anything, such as a public address and the
688
+ * page holding it.
689
+ */
616
690
  static duplicate(opts) {
617
691
  return new NextlyError({
618
692
  code: "DUPLICATE",
619
- publicMessage: "Resource already exists.",
693
+ publicMessage: opts?.message ?? "Resource already exists.",
620
694
  logContext: opts?.logContext
621
695
  });
622
696
  }
@@ -646,6 +720,27 @@ var NextlyError = class NextlyError extends Error {
646
720
  });
647
721
  }
648
722
  /**
723
+ * An access or field rule the request needs could not run, because its own
724
+ * database query waited out the bound for a connection. Not a refusal: the
725
+ * rule never answered. Names the collection or Single whose rule it is, and
726
+ * the field for a field's rule, and says when to retry.
727
+ */
728
+ static ruleCouldNotRun(opts) {
729
+ const publicData = {
730
+ subject: opts.subject,
731
+ ...opts.field !== void 0 ? { field: opts.field } : {},
732
+ retryAfterSeconds: 5
733
+ };
734
+ return new NextlyError({
735
+ code: "RULE_COULD_NOT_RUN",
736
+ statusCode: NEXTLY_ERROR_STATUS.RULE_COULD_NOT_RUN,
737
+ publicMessage: genericPublicMessage("RULE_COULD_NOT_RUN"),
738
+ publicData,
739
+ cause: opts.cause,
740
+ logContext: opts.logContext
741
+ });
742
+ }
743
+ /**
649
744
  * What a request boundary answers with for a thrown value that is not a
650
745
  * NextlyError: "database busy" when the request waited out its bound for a
651
746
  * connection, which is retryable and no fault of the server's code, and an
@@ -765,7 +860,7 @@ var NextlyError = class NextlyError extends Error {
765
860
  return NextlyError.isCode(err, "RATE_LIMITED");
766
861
  }
767
862
  };
768
- // ../nextly/dist/validate-external-url-DpPuwVvV.mjs
863
+ // ../nextly/dist/validate-external-url-DNl_UEVd.mjs
769
864
  /** Default response body cap: reject anything larger before buffering it all. */
770
865
  /**
771
866
  * How many bytes a bounded external read may buffer, absent a caller's own cap.
@@ -933,19 +1028,24 @@ function abortAfter(options) {
933
1028
  }
934
1029
  var S3StorageAdapter = class {
935
1030
  config;
936
- client;
1031
+ client = null;
937
1032
  resolvedConfig;
938
1033
  isR2;
939
1034
  /**
940
1035
  * Create a new S3 storage adapter.
941
1036
  *
1037
+ * The bucket and region are deliberately NOT checked here, and the SDK
1038
+ * client is deliberately not built. This constructor runs while the host's
1039
+ * config file is evaluated, so a throw would stop every command —
1040
+ * including the schema-only ones that never touch storage. Both the checks
1041
+ * and the client construction move to the first storage operation
1042
+ * ({@link ensureClient} and {@link ensureConfigured}), which refuse with
1043
+ * the same messages a missing bucket or region has always produced.
1044
+ *
942
1045
  * @param config - S3 storage configuration
943
- * @throws Error if bucket or region is not provided
944
1046
  */
945
1047
  constructor(config) {
946
1048
  this.config = config;
947
- if (!config.bucket) throw new Error("@nextly/storage-s3: bucket is required");
948
- if (!config.region) throw new Error("@nextly/storage-s3: region is required");
949
1049
  this.isR2 = config.endpoint?.includes("r2.cloudflarestorage.com") ?? false;
950
1050
  this.resolvedConfig = {
951
1051
  bucket: config.bucket,
@@ -958,14 +1058,42 @@ var S3StorageAdapter = class {
958
1058
  contentDisposition: config.contentDisposition,
959
1059
  signedUrlExpiresIn: config.signedUrlExpiresIn ?? 3600
960
1060
  };
1061
+ }
1062
+ /**
1063
+ * Validate that bucket and region are present.
1064
+ *
1065
+ * @throws Error if bucket is not provided
1066
+ * @throws Error if region is not provided
1067
+ */
1068
+ ensureConfigured() {
1069
+ if (!this.config.bucket) throw new Error("@nextly/storage-s3: bucket is required");
1070
+ if (!this.config.region) throw new Error("@nextly/storage-s3: region is required");
1071
+ }
1072
+ /**
1073
+ * Validate the stored configuration and build the SDK client, at the
1074
+ * first use that needs them.
1075
+ *
1076
+ * The refusals are the ones the constructor used to throw, in the same
1077
+ * order, so an operator with a genuinely misconfigured deployment sees
1078
+ * the message they have always seen — at the moment the value was
1079
+ * actually needed rather than at config load. The client is built once
1080
+ * and reused.
1081
+ *
1082
+ * @throws Error if bucket is not provided
1083
+ * @throws Error if region is not provided
1084
+ */
1085
+ ensureClient() {
1086
+ if (this.client) return this.client;
1087
+ this.ensureConfigured();
961
1088
  const credentials = this.buildCredentials();
962
1089
  this.client = new S3Client({
963
- region: config.region,
964
- endpoint: config.endpoint,
1090
+ region: this.config.region,
1091
+ endpoint: this.config.endpoint,
965
1092
  credentials,
966
1093
  forcePathStyle: this.resolvedConfig.forcePathStyle,
967
- ...config.config
1094
+ ...this.config.config
968
1095
  });
1096
+ return this.client;
969
1097
  }
970
1098
  /**
971
1099
  * Build AWS credentials from config.
@@ -992,6 +1120,7 @@ var S3StorageAdapter = class {
992
1120
  * @returns Upload result with URL and storage path
993
1121
  */
994
1122
  async upload(buffer, options) {
1123
+ const client = this.ensureClient();
995
1124
  const key = this.generateKey(options.filename, options.folder);
996
1125
  const uploadParams = {
997
1126
  Bucket: this.resolvedConfig.bucket,
@@ -1008,7 +1137,7 @@ var S3StorageAdapter = class {
1008
1137
  }
1009
1138
  uploadParams.Metadata = { "original-filename": options.filename };
1010
1139
  await new Upload({
1011
- client: this.client,
1140
+ client,
1012
1141
  params: uploadParams
1013
1142
  }).done();
1014
1143
  return {
@@ -1022,11 +1151,12 @@ var S3StorageAdapter = class {
1022
1151
  * @param filePath - Storage path/key to delete
1023
1152
  */
1024
1153
  async delete(filePath) {
1154
+ const client = this.ensureClient();
1025
1155
  const command = new DeleteObjectCommand({
1026
1156
  Bucket: this.resolvedConfig.bucket,
1027
1157
  Key: filePath
1028
1158
  });
1029
- await this.client.send(command);
1159
+ await client.send(command);
1030
1160
  }
1031
1161
  /**
1032
1162
  * Bulk delete files from S3 using a single API call per 1000 keys.
@@ -1038,6 +1168,7 @@ var S3StorageAdapter = class {
1038
1168
  * @returns Object with arrays of successful and failed deletions
1039
1169
  */
1040
1170
  async bulkDelete(filePaths) {
1171
+ const client = this.ensureClient();
1041
1172
  const successful = [];
1042
1173
  const failed = [];
1043
1174
  const maxBatchSize = 1e3;
@@ -1050,7 +1181,7 @@ var S3StorageAdapter = class {
1050
1181
  Quiet: false
1051
1182
  }
1052
1183
  });
1053
- const response = await this.client.send(command);
1184
+ const response = await client.send(command);
1054
1185
  if (response.Errors && response.Errors.length > 0) {
1055
1186
  for (const err of response.Errors) if (err.Key) failed.push({
1056
1187
  filePath: err.Key,
@@ -1076,12 +1207,13 @@ var S3StorageAdapter = class {
1076
1207
  * @returns true if file exists, false otherwise
1077
1208
  */
1078
1209
  async exists(filePath) {
1210
+ const client = this.ensureClient();
1079
1211
  try {
1080
1212
  const command = new HeadObjectCommand({
1081
1213
  Bucket: this.resolvedConfig.bucket,
1082
1214
  Key: filePath
1083
1215
  });
1084
- await this.client.send(command);
1216
+ await client.send(command);
1085
1217
  return true;
1086
1218
  } catch (error) {
1087
1219
  if (this.isNotFoundError(error)) return false;
@@ -1106,9 +1238,10 @@ var S3StorageAdapter = class {
1106
1238
  * of up to 1,000 at a time.
1107
1239
  */
1108
1240
  async *list() {
1241
+ const client = this.ensureClient();
1109
1242
  let token;
1110
1243
  do {
1111
- const page = await this.client.send(new ListObjectsV2Command({
1244
+ const page = await client.send(new ListObjectsV2Command({
1112
1245
  Bucket: this.resolvedConfig.bucket,
1113
1246
  ContinuationToken: token
1114
1247
  }));
@@ -1120,6 +1253,7 @@ var S3StorageAdapter = class {
1120
1253
  } while (token);
1121
1254
  }
1122
1255
  getPublicUrl(filePath) {
1256
+ this.ensureConfigured();
1123
1257
  if (this.resolvedConfig.publicUrl) return `${this.resolvedConfig.publicUrl.replace(/\/$/, "")}/${filePath}`;
1124
1258
  if (this.isR2) throw new Error("@nextly/storage-s3: Cloudflare R2 requires publicUrl configuration.\n\nR2 does not have default public URLs like AWS S3. Configure one of:\n1. Public bucket URL: publicUrl: 'https://pub-xxx.r2.dev'\n2. Custom domain: publicUrl: 'https://cdn.example.com'\n\nSet up public access in the Cloudflare R2 dashboard.");
1125
1259
  return `https://${this.resolvedConfig.bucket}.s3.${this.resolvedConfig.region}.amazonaws.com/${filePath}`;
@@ -1156,12 +1290,13 @@ var S3StorageAdapter = class {
1156
1290
  * @returns File metadata or null if file not found
1157
1291
  */
1158
1292
  async getMetadata(filePath) {
1293
+ const client = this.ensureClient();
1159
1294
  try {
1160
1295
  const command = new HeadObjectCommand({
1161
1296
  Bucket: this.resolvedConfig.bucket,
1162
1297
  Key: filePath
1163
1298
  });
1164
- const response = await this.client.send(command);
1299
+ const response = await client.send(command);
1165
1300
  const filename = filePath.split("/").pop() || filePath;
1166
1301
  return {
1167
1302
  id: filePath,
@@ -1202,12 +1337,13 @@ var S3StorageAdapter = class {
1202
1337
  * @returns The object's bytes, or `null` when no such key exists
1203
1338
  */
1204
1339
  async read(filePath, options) {
1340
+ const client = this.ensureClient();
1205
1341
  try {
1206
1342
  const command = new GetObjectCommand({
1207
1343
  Bucket: this.resolvedConfig.bucket,
1208
1344
  Key: filePath
1209
1345
  });
1210
- const response = await this.client.send(command, abortAfter(options));
1346
+ const response = await client.send(command, abortAfter(options));
1211
1347
  if (response.Body === void 0) return Buffer.alloc(0);
1212
1348
  const cap = resolveReadBounds(options).maxBytes;
1213
1349
  this.refuseOverCap(filePath, response.ContentLength, cap);
@@ -1229,11 +1365,12 @@ var S3StorageAdapter = class {
1229
1365
  * @returns Pre-signed URL for downloading the file
1230
1366
  */
1231
1367
  async getSignedUrl(filePath, expiresIn) {
1368
+ const client = this.ensureClient();
1232
1369
  const command = new GetObjectCommand({
1233
1370
  Bucket: this.resolvedConfig.bucket,
1234
1371
  Key: filePath
1235
1372
  });
1236
- return getSignedUrl(this.client, command, { expiresIn: expiresIn ?? this.resolvedConfig.signedUrlExpiresIn });
1373
+ return getSignedUrl(client, command, { expiresIn: expiresIn ?? this.resolvedConfig.signedUrlExpiresIn });
1237
1374
  }
1238
1375
  /**
1239
1376
  * Generate pre-signed URL for client-side uploads.
@@ -1247,6 +1384,7 @@ var S3StorageAdapter = class {
1247
1384
  * @returns Client upload data with URL, method, and headers
1248
1385
  */
1249
1386
  async getPresignedUploadUrl(key, mimeType, expiresIn) {
1387
+ const client = this.ensureClient();
1250
1388
  const expiration = expiresIn ?? this.resolvedConfig.signedUrlExpiresIn;
1251
1389
  const commandParams = {
1252
1390
  Bucket: this.resolvedConfig.bucket,
@@ -1257,7 +1395,7 @@ var S3StorageAdapter = class {
1257
1395
  if (!this.isR2) commandParams.ACL = this.resolvedConfig.acl;
1258
1396
  const command = new PutObjectCommand(commandParams);
1259
1397
  return {
1260
- uploadUrl: await getSignedUrl(this.client, command, { expiresIn: expiration }),
1398
+ uploadUrl: await getSignedUrl(client, command, { expiresIn: expiration }),
1261
1399
  path: key,
1262
1400
  method: "PUT",
1263
1401
  headers: { "Content-Type": mimeType },
@@ -1356,9 +1494,13 @@ var S3StorageAdapter = class {
1356
1494
  /**
1357
1495
  * Get the S3 client instance.
1358
1496
  * Useful for advanced operations not covered by the adapter interface.
1497
+ *
1498
+ * Handing out the client is itself a use of the adapter, so a caller
1499
+ * without the configuration a client needs is refused here like any
1500
+ * other operation.
1359
1501
  */
1360
1502
  getClient() {
1361
- return this.client;
1503
+ return this.ensureClient();
1362
1504
  }
1363
1505
  /**
1364
1506
  * Get the bucket name.
@@ -1395,8 +1537,8 @@ var S3StorageAdapter = class {
1395
1537
  * @param config - S3 storage configuration
1396
1538
  * @returns A StoragePlugin that MediaStorage can register
1397
1539
  *
1398
- * @throws Error if bucket is not provided (via adapter)
1399
- * @throws Error if region is not provided (via adapter)
1540
+ * Constructing the plugin never requires the bucket or region: a missing
1541
+ * one is refused when storage is first used, not while the config loads.
1400
1542
  */
1401
1543
  function s3Storage(config) {
1402
1544
  if (config.enabled === false) return {