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