@nextlyhq/storage-s3 0.0.2-alpha.72 → 0.0.2-alpha.74

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.cjs CHANGED
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
3
3
  let _aws_sdk_lib_storage = require("@aws-sdk/lib-storage");
4
4
  let _aws_sdk_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
5
- // ../nextly/dist/nextly-error-DetCjZnO.mjs
5
+ // ../nextly/dist/nextly-error-D08zf_L_.mjs
6
6
  function isDbError(err) {
7
7
  if (!err || typeof err !== "object") return false;
8
8
  const obj = err;
@@ -78,10 +78,15 @@ const NEXTLY_ERROR_STATUS = {
78
78
  CSRF_FAILED: 403,
79
79
  SETUP_TOKEN_REQUIRED: 403,
80
80
  API_KEY_ROLE_ABOVE_CREATOR: 403,
81
+ ACTION_NOT_AVAILABLE: 403,
81
82
  NOT_FOUND: 404,
83
+ ENTITY_REMOVED_FROM_CODE: 409,
84
+ ENTITY_NOT_MIGRATED: 409,
82
85
  METHOD_NOT_ALLOWED: 405,
83
86
  RANGE_NOT_SATISFIABLE: 416,
84
87
  CONFLICT: 409,
88
+ STALE_VERSION: 409,
89
+ VERSION_REQUIRED: 428,
85
90
  DUPLICATE: 409,
86
91
  RATE_LIMITED: 429,
87
92
  PAYLOAD_TOO_LARGE: 413,
@@ -90,8 +95,10 @@ const NEXTLY_ERROR_STATUS = {
90
95
  INTERNAL_ERROR: 500,
91
96
  DATABASE_ERROR: 500,
92
97
  DATABASE_BUSY: 503,
98
+ RULE_COULD_NOT_RUN: 503,
93
99
  EXTERNAL_SERVICE_ERROR: 502,
94
100
  SERVICE_UNAVAILABLE: 503,
101
+ CONFIGURATION_ERROR: 500,
95
102
  EXTERNAL_URL_BLOCKED: 400,
96
103
  EXTERNAL_REQUEST_FAILED: 502,
97
104
  FILENAME_INVALID: 400,
@@ -133,11 +140,13 @@ const NEXTLY_ERROR_STATUS = {
133
140
  NEXTLY_SCHEMA_RENAME_UNKNOWN_TARGET: 400,
134
141
  NEXTLY_PLUGIN_CLIENT_CONFIG_INVALID: 500,
135
142
  NEXTLY_PLUGIN_ADMIN_WIDGET_INVALID: 500,
136
- NEXTLY_ADMIN_COMPONENT_MAP_STALE: 500,
143
+ NEXTLY_PLUGIN_REMOVED_WIDGET_CHANNEL: 500,
137
144
  NEXTLY_PLUGIN_DOCUMENT_VIEW_INVALID: 500,
145
+ NEXTLY_PLUGIN_DOCUMENT_SURFACE_INVALID: 500,
138
146
  PLUGIN_RESOLUTION_ERROR: 500,
139
147
  PLUGIN_DEPENDENCY_NOT_INSTALLED: 409,
140
148
  PLUGIN_HAS_DEPENDENTS: 409,
149
+ PLUGIN_UNINSTALL_WOULD_DROP_OTHERS: 409,
141
150
  PLUGIN_UNINSTALL_IRREVERSIBLE: 409,
142
151
  PLUGIN_UNINSTALL_UNCONFIRMED: 409,
143
152
  PLUGIN_SCHEMA_BEHIND: 409,
@@ -161,6 +170,9 @@ const NEXTLY_ERROR_STATUS = {
161
170
  NEXTLY_EMAIL_TRANSPORT_UNAVAILABLE: 503,
162
171
  NEXTLY_CONFIG_TOOLING_UNAVAILABLE: 503,
163
172
  NEXTLY_POSTGRES_SCHEMA_MISMATCH: 500,
173
+ NEXTLY_PER_LANGUAGE_STORAGE_CHANGED: 500,
174
+ NEXTLY_PER_LANGUAGE_STORAGE_MIXED: 500,
175
+ NEXTLY_PER_LANGUAGE_STORAGE_LANGUAGES_UNDECLARED: 500,
164
176
  NEXTLY_POSTGRES_SCHEMA_UNSUPPORTED: 500
165
177
  };
166
178
  ({ ...Object.fromEntries([
@@ -169,6 +181,7 @@ const NEXTLY_ERROR_STATUS = {
169
181
  "FORBIDDEN",
170
182
  "NOT_FOUND",
171
183
  "CONFLICT",
184
+ "VERSION_REQUIRED",
172
185
  "PAYLOAD_TOO_LARGE",
173
186
  "UNSUPPORTED_MEDIA_TYPE",
174
187
  "RATE_LIMITED",
@@ -192,6 +205,7 @@ const GENERIC_PUBLIC_MESSAGE = {
192
205
  INVALID_INPUT: "The request could not be processed.",
193
206
  AUTH_REQUIRED: "Authentication required.",
194
207
  FORBIDDEN: "You don't have permission to perform this action.",
208
+ ACTION_NOT_AVAILABLE: "This action isn't available for this entry.",
195
209
  NOT_FOUND: "Not found.",
196
210
  METHOD_NOT_ALLOWED: "That method is not allowed on this address.",
197
211
  RANGE_NOT_SATISFIABLE: "The requested range is outside the file.",
@@ -203,6 +217,7 @@ const GENERIC_PUBLIC_MESSAGE = {
203
217
  EXTERNAL_SERVICE_ERROR: "An upstream service failed.",
204
218
  SERVICE_UNAVAILABLE: "The service is temporarily unavailable.",
205
219
  DATABASE_BUSY: "The database is busy. Please try again shortly.",
220
+ RULE_COULD_NOT_RUN: "A check this request needs could not run. Please try again shortly.",
206
221
  INTERNAL_ERROR: "An unexpected error occurred."
207
222
  };
208
223
  /** The generic sentence for a code; the internal one for anything unlisted. */
@@ -410,6 +425,7 @@ var NextlyError = class NextlyError extends Error {
410
425
  return new NextlyError({
411
426
  code: "FORBIDDEN",
412
427
  publicMessage: "You don't have permission to perform this action.",
428
+ publicData: opts?.publicData,
413
429
  cause: opts?.cause,
414
430
  logContext: opts?.logContext
415
431
  });
@@ -433,9 +449,15 @@ var NextlyError = class NextlyError extends Error {
433
449
  * not about the caller's permissions.
434
450
  */
435
451
  static builtIn(opts) {
452
+ const done = {
453
+ change: "changed",
454
+ delete: "deleted",
455
+ assign: "assigned",
456
+ inherit: "inherited"
457
+ }[opts.change];
436
458
  return new NextlyError({
437
459
  code: "FORBIDDEN",
438
- publicMessage: `This ${opts.thing} is built in, so it can't be ${opts.change === "change" ? "changed" : "deleted"}.`,
460
+ publicMessage: `This ${opts.thing} is built in, so it can't be ${done}.`,
439
461
  logContext: opts.logContext
440
462
  });
441
463
  }
@@ -478,6 +500,57 @@ var NextlyError = class NextlyError extends Error {
478
500
  });
479
501
  }
480
502
  /**
503
+ * A write to an entry of a collection or Single removed from code: its
504
+ * registry row says the app's code defines it, and the running configuration
505
+ * no longer declares it. Its entries are read-only until it is retired or
506
+ * declared again, so the message names the entity, says what happened and
507
+ * gives both ways out. `publicData` carries the kind and the slug, which the
508
+ * caller named, so a client can mark the entity without parsing the sentence.
509
+ */
510
+ static removedFromCode(opts) {
511
+ const thing = opts.kind === "single" ? "Single" : "collection";
512
+ const its = opts.kind === "single" ? "it" : "its entries";
513
+ return new NextlyError({
514
+ code: "ENTITY_REMOVED_FROM_CODE",
515
+ publicMessage: `The ${thing} "${opts.slug}" was removed from code, so ${its} can't be changed. To retire it, run \`nextly migrate:create\` and then \`nextly migrate\`. To keep it, declare it again in nextly.config.ts.`,
516
+ publicData: {
517
+ kind: opts.kind,
518
+ slug: opts.slug
519
+ },
520
+ logContext: {
521
+ kind: opts.kind,
522
+ slug: opts.slug,
523
+ ...opts.logContext
524
+ }
525
+ });
526
+ }
527
+ /**
528
+ * A read or write of a collection or Single the database has not been
529
+ * migrated for: the column of one of its declared fields is missing, its
530
+ * table is missing, or this running instance never registered it (an
531
+ * entity a migration added after the instance started). The message names
532
+ * the entity, the field or the table, and `nextly migrate`; the driver's
533
+ * error stays on `cause`, for the log, so no SQL reaches the answer.
534
+ */
535
+ static notMigrated(opts) {
536
+ const { cause, logContext, ...publicData } = opts;
537
+ const entity = `${publicData.kind === "single" ? "Single" : "collection"} "${publicData.slug}"`;
538
+ const field = publicData.field === void 0 ? "a field" : `the field "${publicData.field}"`;
539
+ const table = publicData.table === void 0 ? "" : ` "${publicData.table}"`;
540
+ const publicMessage = publicData.reason === "column" ? `The database has not been migrated for ${field} of the ${entity}. Run \`nextly migrate\`.` : publicData.reason === "table" ? `The database has not been migrated for the ${entity}: its table${table} does not exist. Run \`nextly migrate\`.` : `The ${entity}${publicData.table === void 0 ? "" : ` (table "${publicData.table}")`} is not registered in this running instance. Run \`nextly migrate\`, then restart the server.`;
541
+ return new NextlyError({
542
+ code: "ENTITY_NOT_MIGRATED",
543
+ publicMessage,
544
+ publicData,
545
+ logMessage: "The database has not been migrated for this entity",
546
+ logContext: {
547
+ ...publicData,
548
+ ...logContext
549
+ },
550
+ cause
551
+ });
552
+ }
553
+ /**
481
554
  * An autosave where the collection or Single does not autosave: its owner
482
555
  * switched autosave off, or it keeps no drafts to autosave into. Forbidden,
483
556
  * and the message says so, since it is a setting and not a permission.
@@ -554,6 +627,60 @@ var NextlyError = class NextlyError extends Error {
554
627
  }
555
628
  });
556
629
  }
630
+ /**
631
+ * An update made from a version of the document that is no longer its
632
+ * current one. Never retried: the same version stays out of date, so the
633
+ * caller must read the document again and decide.
634
+ *
635
+ * @experimental
636
+ */
637
+ /**
638
+ * An update that said neither which version of a document it was made from
639
+ * nor that it overwrites whatever is stored. Without `bulk`, an update of
640
+ * one document, which sends back the version it read. `bulk` names an
641
+ * update that writes the same values to many documents, which can carry no
642
+ * one document's version: by its ids, which can be given a version each
643
+ * (`keys.revs`), or by a query, which cannot. The keys are the write path's
644
+ * to name, so the message spells them as the request does.
645
+ *
646
+ * @experimental
647
+ */
648
+ static versionRequired(opts) {
649
+ const { version, overwrite, revs } = opts.keys;
650
+ if (opts.bulk === void 0) {
651
+ const one = {
652
+ versionKey: version,
653
+ overwriteKey: overwrite
654
+ };
655
+ return new NextlyError({
656
+ code: "VERSION_REQUIRED",
657
+ 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.`,
658
+ publicData: one,
659
+ logContext: opts.logContext
660
+ });
661
+ }
662
+ const byIds = opts.bulk === "ids";
663
+ const data = {
664
+ versionKey: version,
665
+ overwriteKey: overwrite,
666
+ ...byIds ? { revsKey: revs } : {}
667
+ };
668
+ 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}\`.`;
669
+ return new NextlyError({
670
+ code: "VERSION_REQUIRED",
671
+ publicMessage: byIds ? `${message} Or give each document's \`${version}\` in \`${revs}\`.` : message,
672
+ publicData: data,
673
+ logContext: opts.logContext
674
+ });
675
+ }
676
+ static staleVersion(opts) {
677
+ return new NextlyError({
678
+ code: "STALE_VERSION",
679
+ publicMessage: `This document changed since the version you gave. Its current version is ${opts.data.currentVersion}.`,
680
+ publicData: opts.data,
681
+ logContext: opts.logContext
682
+ });
683
+ }
557
684
  static duplicate(opts) {
558
685
  return new NextlyError({
559
686
  code: "DUPLICATE",
@@ -587,6 +714,27 @@ var NextlyError = class NextlyError extends Error {
587
714
  });
588
715
  }
589
716
  /**
717
+ * An access or field rule the request needs could not run, because its own
718
+ * database query waited out the bound for a connection. Not a refusal: the
719
+ * rule never answered. Names the collection or Single whose rule it is, and
720
+ * the field for a field's rule, and says when to retry.
721
+ */
722
+ static ruleCouldNotRun(opts) {
723
+ const publicData = {
724
+ subject: opts.subject,
725
+ ...opts.field !== void 0 ? { field: opts.field } : {},
726
+ retryAfterSeconds: 5
727
+ };
728
+ return new NextlyError({
729
+ code: "RULE_COULD_NOT_RUN",
730
+ statusCode: NEXTLY_ERROR_STATUS.RULE_COULD_NOT_RUN,
731
+ publicMessage: genericPublicMessage("RULE_COULD_NOT_RUN"),
732
+ publicData,
733
+ cause: opts.cause,
734
+ logContext: opts.logContext
735
+ });
736
+ }
737
+ /**
590
738
  * What a request boundary answers with for a thrown value that is not a
591
739
  * NextlyError: "database busy" when the request waited out its bound for a
592
740
  * connection, which is retryable and no fault of the server's code, and an
@@ -621,6 +769,19 @@ var NextlyError = class NextlyError extends Error {
621
769
  logContext: opts?.logContext
622
770
  });
623
771
  }
772
+ /**
773
+ * The app is set up so nextly cannot work: a missing `config`, or a Next.js
774
+ * or React outside the supported ranges. The public message stays generic;
775
+ * what to change goes in `logMessage`, for the operator.
776
+ */
777
+ static configuration(opts) {
778
+ return new NextlyError({
779
+ code: "CONFIGURATION_ERROR",
780
+ publicMessage: "Server configuration error.",
781
+ logMessage: opts.logMessage,
782
+ logContext: opts.logContext
783
+ });
784
+ }
624
785
  static serviceUnavailable(opts) {
625
786
  return new NextlyError({
626
787
  code: "SERVICE_UNAVAILABLE",
@@ -693,7 +854,7 @@ var NextlyError = class NextlyError extends Error {
693
854
  return NextlyError.isCode(err, "RATE_LIMITED");
694
855
  }
695
856
  };
696
- // ../nextly/dist/validate-external-url-CfT2WjgH.mjs
857
+ // ../nextly/dist/validate-external-url-BKFCMuwY.mjs
697
858
  /** Default response body cap: reject anything larger before buffering it all. */
698
859
  /**
699
860
  * How many bytes a bounded external read may buffer, absent a caller's own cap.
@@ -861,19 +1022,24 @@ function abortAfter(options) {
861
1022
  }
862
1023
  var S3StorageAdapter = class {
863
1024
  config;
864
- client;
1025
+ client = null;
865
1026
  resolvedConfig;
866
1027
  isR2;
867
1028
  /**
868
1029
  * Create a new S3 storage adapter.
869
1030
  *
1031
+ * The bucket and region are deliberately NOT checked here, and the SDK
1032
+ * client is deliberately not built. This constructor runs while the host's
1033
+ * config file is evaluated, so a throw would stop every command —
1034
+ * including the schema-only ones that never touch storage. Both the checks
1035
+ * and the client construction move to the first storage operation
1036
+ * ({@link ensureClient} and {@link ensureConfigured}), which refuse with
1037
+ * the same messages a missing bucket or region has always produced.
1038
+ *
870
1039
  * @param config - S3 storage configuration
871
- * @throws Error if bucket or region is not provided
872
1040
  */
873
1041
  constructor(config) {
874
1042
  this.config = config;
875
- if (!config.bucket) throw new Error("@nextly/storage-s3: bucket is required");
876
- if (!config.region) throw new Error("@nextly/storage-s3: region is required");
877
1043
  this.isR2 = config.endpoint?.includes("r2.cloudflarestorage.com") ?? false;
878
1044
  this.resolvedConfig = {
879
1045
  bucket: config.bucket,
@@ -886,14 +1052,42 @@ var S3StorageAdapter = class {
886
1052
  contentDisposition: config.contentDisposition,
887
1053
  signedUrlExpiresIn: config.signedUrlExpiresIn ?? 3600
888
1054
  };
1055
+ }
1056
+ /**
1057
+ * Validate that bucket and region are present.
1058
+ *
1059
+ * @throws Error if bucket is not provided
1060
+ * @throws Error if region is not provided
1061
+ */
1062
+ ensureConfigured() {
1063
+ if (!this.config.bucket) throw new Error("@nextly/storage-s3: bucket is required");
1064
+ if (!this.config.region) throw new Error("@nextly/storage-s3: region is required");
1065
+ }
1066
+ /**
1067
+ * Validate the stored configuration and build the SDK client, at the
1068
+ * first use that needs them.
1069
+ *
1070
+ * The refusals are the ones the constructor used to throw, in the same
1071
+ * order, so an operator with a genuinely misconfigured deployment sees
1072
+ * the message they have always seen — at the moment the value was
1073
+ * actually needed rather than at config load. The client is built once
1074
+ * and reused.
1075
+ *
1076
+ * @throws Error if bucket is not provided
1077
+ * @throws Error if region is not provided
1078
+ */
1079
+ ensureClient() {
1080
+ if (this.client) return this.client;
1081
+ this.ensureConfigured();
889
1082
  const credentials = this.buildCredentials();
890
1083
  this.client = new _aws_sdk_client_s3.S3Client({
891
- region: config.region,
892
- endpoint: config.endpoint,
1084
+ region: this.config.region,
1085
+ endpoint: this.config.endpoint,
893
1086
  credentials,
894
1087
  forcePathStyle: this.resolvedConfig.forcePathStyle,
895
- ...config.config
1088
+ ...this.config.config
896
1089
  });
1090
+ return this.client;
897
1091
  }
898
1092
  /**
899
1093
  * Build AWS credentials from config.
@@ -920,6 +1114,7 @@ var S3StorageAdapter = class {
920
1114
  * @returns Upload result with URL and storage path
921
1115
  */
922
1116
  async upload(buffer, options) {
1117
+ const client = this.ensureClient();
923
1118
  const key = this.generateKey(options.filename, options.folder);
924
1119
  const uploadParams = {
925
1120
  Bucket: this.resolvedConfig.bucket,
@@ -936,7 +1131,7 @@ var S3StorageAdapter = class {
936
1131
  }
937
1132
  uploadParams.Metadata = { "original-filename": options.filename };
938
1133
  await new _aws_sdk_lib_storage.Upload({
939
- client: this.client,
1134
+ client,
940
1135
  params: uploadParams
941
1136
  }).done();
942
1137
  return {
@@ -950,11 +1145,12 @@ var S3StorageAdapter = class {
950
1145
  * @param filePath - Storage path/key to delete
951
1146
  */
952
1147
  async delete(filePath) {
1148
+ const client = this.ensureClient();
953
1149
  const command = new _aws_sdk_client_s3.DeleteObjectCommand({
954
1150
  Bucket: this.resolvedConfig.bucket,
955
1151
  Key: filePath
956
1152
  });
957
- await this.client.send(command);
1153
+ await client.send(command);
958
1154
  }
959
1155
  /**
960
1156
  * Bulk delete files from S3 using a single API call per 1000 keys.
@@ -966,6 +1162,7 @@ var S3StorageAdapter = class {
966
1162
  * @returns Object with arrays of successful and failed deletions
967
1163
  */
968
1164
  async bulkDelete(filePaths) {
1165
+ const client = this.ensureClient();
969
1166
  const successful = [];
970
1167
  const failed = [];
971
1168
  const maxBatchSize = 1e3;
@@ -978,7 +1175,7 @@ var S3StorageAdapter = class {
978
1175
  Quiet: false
979
1176
  }
980
1177
  });
981
- const response = await this.client.send(command);
1178
+ const response = await client.send(command);
982
1179
  if (response.Errors && response.Errors.length > 0) {
983
1180
  for (const err of response.Errors) if (err.Key) failed.push({
984
1181
  filePath: err.Key,
@@ -1004,12 +1201,13 @@ var S3StorageAdapter = class {
1004
1201
  * @returns true if file exists, false otherwise
1005
1202
  */
1006
1203
  async exists(filePath) {
1204
+ const client = this.ensureClient();
1007
1205
  try {
1008
1206
  const command = new _aws_sdk_client_s3.HeadObjectCommand({
1009
1207
  Bucket: this.resolvedConfig.bucket,
1010
1208
  Key: filePath
1011
1209
  });
1012
- await this.client.send(command);
1210
+ await client.send(command);
1013
1211
  return true;
1014
1212
  } catch (error) {
1015
1213
  if (this.isNotFoundError(error)) return false;
@@ -1034,9 +1232,10 @@ var S3StorageAdapter = class {
1034
1232
  * of up to 1,000 at a time.
1035
1233
  */
1036
1234
  async *list() {
1235
+ const client = this.ensureClient();
1037
1236
  let token;
1038
1237
  do {
1039
- const page = await this.client.send(new _aws_sdk_client_s3.ListObjectsV2Command({
1238
+ const page = await client.send(new _aws_sdk_client_s3.ListObjectsV2Command({
1040
1239
  Bucket: this.resolvedConfig.bucket,
1041
1240
  ContinuationToken: token
1042
1241
  }));
@@ -1048,6 +1247,7 @@ var S3StorageAdapter = class {
1048
1247
  } while (token);
1049
1248
  }
1050
1249
  getPublicUrl(filePath) {
1250
+ this.ensureConfigured();
1051
1251
  if (this.resolvedConfig.publicUrl) return `${this.resolvedConfig.publicUrl.replace(/\/$/, "")}/${filePath}`;
1052
1252
  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.");
1053
1253
  return `https://${this.resolvedConfig.bucket}.s3.${this.resolvedConfig.region}.amazonaws.com/${filePath}`;
@@ -1084,12 +1284,13 @@ var S3StorageAdapter = class {
1084
1284
  * @returns File metadata or null if file not found
1085
1285
  */
1086
1286
  async getMetadata(filePath) {
1287
+ const client = this.ensureClient();
1087
1288
  try {
1088
1289
  const command = new _aws_sdk_client_s3.HeadObjectCommand({
1089
1290
  Bucket: this.resolvedConfig.bucket,
1090
1291
  Key: filePath
1091
1292
  });
1092
- const response = await this.client.send(command);
1293
+ const response = await client.send(command);
1093
1294
  const filename = filePath.split("/").pop() || filePath;
1094
1295
  return {
1095
1296
  id: filePath,
@@ -1130,12 +1331,13 @@ var S3StorageAdapter = class {
1130
1331
  * @returns The object's bytes, or `null` when no such key exists
1131
1332
  */
1132
1333
  async read(filePath, options) {
1334
+ const client = this.ensureClient();
1133
1335
  try {
1134
1336
  const command = new _aws_sdk_client_s3.GetObjectCommand({
1135
1337
  Bucket: this.resolvedConfig.bucket,
1136
1338
  Key: filePath
1137
1339
  });
1138
- const response = await this.client.send(command, abortAfter(options));
1340
+ const response = await client.send(command, abortAfter(options));
1139
1341
  if (response.Body === void 0) return Buffer.alloc(0);
1140
1342
  const cap = resolveReadBounds(options).maxBytes;
1141
1343
  this.refuseOverCap(filePath, response.ContentLength, cap);
@@ -1157,11 +1359,12 @@ var S3StorageAdapter = class {
1157
1359
  * @returns Pre-signed URL for downloading the file
1158
1360
  */
1159
1361
  async getSignedUrl(filePath, expiresIn) {
1362
+ const client = this.ensureClient();
1160
1363
  const command = new _aws_sdk_client_s3.GetObjectCommand({
1161
1364
  Bucket: this.resolvedConfig.bucket,
1162
1365
  Key: filePath
1163
1366
  });
1164
- return (0, _aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn: expiresIn ?? this.resolvedConfig.signedUrlExpiresIn });
1367
+ return (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: expiresIn ?? this.resolvedConfig.signedUrlExpiresIn });
1165
1368
  }
1166
1369
  /**
1167
1370
  * Generate pre-signed URL for client-side uploads.
@@ -1175,6 +1378,7 @@ var S3StorageAdapter = class {
1175
1378
  * @returns Client upload data with URL, method, and headers
1176
1379
  */
1177
1380
  async getPresignedUploadUrl(key, mimeType, expiresIn) {
1381
+ const client = this.ensureClient();
1178
1382
  const expiration = expiresIn ?? this.resolvedConfig.signedUrlExpiresIn;
1179
1383
  const commandParams = {
1180
1384
  Bucket: this.resolvedConfig.bucket,
@@ -1185,7 +1389,7 @@ var S3StorageAdapter = class {
1185
1389
  if (!this.isR2) commandParams.ACL = this.resolvedConfig.acl;
1186
1390
  const command = new _aws_sdk_client_s3.PutObjectCommand(commandParams);
1187
1391
  return {
1188
- uploadUrl: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(this.client, command, { expiresIn: expiration }),
1392
+ uploadUrl: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: expiration }),
1189
1393
  path: key,
1190
1394
  method: "PUT",
1191
1395
  headers: { "Content-Type": mimeType },
@@ -1284,9 +1488,13 @@ var S3StorageAdapter = class {
1284
1488
  /**
1285
1489
  * Get the S3 client instance.
1286
1490
  * Useful for advanced operations not covered by the adapter interface.
1491
+ *
1492
+ * Handing out the client is itself a use of the adapter, so a caller
1493
+ * without the configuration a client needs is refused here like any
1494
+ * other operation.
1287
1495
  */
1288
1496
  getClient() {
1289
- return this.client;
1497
+ return this.ensureClient();
1290
1498
  }
1291
1499
  /**
1292
1500
  * Get the bucket name.
@@ -1323,8 +1531,8 @@ var S3StorageAdapter = class {
1323
1531
  * @param config - S3 storage configuration
1324
1532
  * @returns A StoragePlugin that MediaStorage can register
1325
1533
  *
1326
- * @throws Error if bucket is not provided (via adapter)
1327
- * @throws Error if region is not provided (via adapter)
1534
+ * Constructing the plugin never requires the bucket or region: a missing
1535
+ * one is refused when storage is first used, not while the config loads.
1328
1536
  */
1329
1537
  function s3Storage(config) {
1330
1538
  if (config.enabled === false) return {