@hot-updater/cloudflare 1.0.0-rc.43 → 1.0.0-rc.45

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
@@ -26,9 +26,7 @@ let cloudflare = require("cloudflare");
26
26
  cloudflare = __toESM(cloudflare, 1);
27
27
  let _aws_sdk_client_s3 = require("@aws-sdk/client-s3");
28
28
  let _aws_sdk_lib_storage = require("@aws-sdk/lib-storage");
29
- let _hot_updater_server_plugins_api_keys = require("@hot-updater/server/plugins/api-keys");
30
- let _hot_updater_server_plugins_insights = require("@hot-updater/server/plugins/insights");
31
- let _hot_updater_server_plugins_remote_config = require("@hot-updater/server/plugins/remote-config");
29
+ let _aws_sdk_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
32
30
  //#region src/d1Executor.ts
33
31
  var D1ExecutionError = class extends Error {
34
32
  name = "D1ExecutionError";
@@ -134,12 +132,14 @@ const d1Database = (config) => {
134
132
  };
135
133
  //#endregion
136
134
  //#region src/r2S3Storage.ts
135
+ /** Devices download right after the update check that returns the URL. */
136
+ const PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
137
137
  const isObjectNotFoundError = (error) => {
138
138
  if (error instanceof Error && (error.name === "NotFound" || error.name === "NoSuchKey")) return true;
139
139
  return typeof error === "object" && error !== null && "$metadata" in error && error.$metadata?.httpStatusCode === 404;
140
140
  };
141
141
  const createR2S3Storage = (config) => {
142
- const { accountId, basePath, bucketName, downloadUrlSigningKey, endpoint, forcePathStyle, region, ...s3Config } = config;
142
+ const { accountId, basePath, bucketName, endpoint, forcePathStyle, region, ...s3Config } = config;
143
143
  const client = new _aws_sdk_client_s3.S3Client({
144
144
  ...s3Config,
145
145
  endpoint: endpoint ?? `https://${accountId}.r2.cloudflarestorage.com`,
@@ -147,7 +147,6 @@ const createR2S3Storage = (config) => {
147
147
  region: region ?? "auto"
148
148
  });
149
149
  const getStorageKey = (0, _hot_updater_plugin_core.createStorageKeyBuilder)(basePath);
150
- const getDownloadUrl = downloadUrlSigningKey ? (0, _hot_updater_plugin_core.createStorageDownloadUrl)(downloadUrlSigningKey) : void 0;
151
150
  const parseAndValidate = (storageUri) => {
152
151
  const parsed = (0, _hot_updater_plugin_core.parseStorageUri)(storageUri, "r2");
153
152
  if (parsed.bucket !== bucketName) throw new Error(`Bucket name mismatch: expected "${bucketName}", but found "${parsed.bucket}".`);
@@ -192,10 +191,13 @@ const createR2S3Storage = (config) => {
192
191
  throw error;
193
192
  }
194
193
  },
195
- ...getDownloadUrl ? { async getDownloadUrl({ storageUri }) {
196
- parseAndValidate(storageUri);
197
- return getDownloadUrl({ storageUri });
198
- } } : {},
194
+ async getDownloadUrl({ storageUri }) {
195
+ const { key } = parseAndValidate(storageUri);
196
+ return { url: await (0, _aws_sdk_s3_request_presigner.getSignedUrl)(client, new _aws_sdk_client_s3.GetObjectCommand({
197
+ Bucket: bucketName,
198
+ Key: key
199
+ }), { expiresIn: PRESIGNED_URL_EXPIRES_IN_SECONDS }) };
200
+ },
199
201
  async exists({ storageUri }) {
200
202
  const { key } = parseAndValidate(storageUri);
201
203
  try {
@@ -222,22 +224,10 @@ const createR2S3Storage = (config) => {
222
224
  //#endregion
223
225
  //#region src/r2Storage.ts
224
226
  const r2Storage = (config) => {
225
- if (!config.credentials) throw new Error("r2Storage requires S3-compatible credentials. The Wrangler fallback was removed.");
227
+ if (!config.credentials) throw new Error("r2Storage requires S3-compatible credentials: pass credentials with an R2 access key ID and secret access key.");
226
228
  return createR2S3Storage(config);
227
229
  };
228
230
  //#endregion
229
- //#region src/plugins.ts
230
- /**
231
- * The plugins the managed Cloudflare server runs: Insights, API keys on every
232
- * client route, and Remote Config. Its Worker imports this list.
233
- */
234
- const plugins = [
235
- (0, _hot_updater_server_plugins_insights.insights)(),
236
- (0, _hot_updater_server_plugins_api_keys.apiKeys)(),
237
- (0, _hot_updater_server_plugins_remote_config.remoteConfig)()
238
- ];
239
- //#endregion
240
231
  exports.D1ExecutionError = D1ExecutionError;
241
232
  exports.d1Database = d1Database;
242
- exports.plugins = plugins;
243
233
  exports.r2Storage = r2Storage;