@hot-updater/standalone 0.12.6 → 0.13.0

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
@@ -3298,18 +3298,20 @@ var __webpack_exports__ = {};
3298
3298
  throw new Error(error);
3299
3299
  }
3300
3300
  const result = await response.json();
3301
- if (!result.fileUrl) {
3302
- const error = "Failed to upload bundle - no fileUrl in response";
3301
+ if (!result.bucketName || !result.key) {
3302
+ const error = "Failed to upload bundle - no bucketName or key in response";
3303
3303
  console.error(`[uploadBundle] ${error}`);
3304
3304
  throw new Error(error);
3305
3305
  }
3306
3306
  hooks?.onStorageUploaded?.();
3307
3307
  return {
3308
- fileUrl: result.fileUrl
3308
+ bucketName: result.bucketName,
3309
+ key: result.key
3309
3310
  };
3310
3311
  }
3311
3312
  };
3312
3313
  };
3314
+ const plugin_core_namespaceObject = require("@hot-updater/plugin-core");
3313
3315
  const standaloneRepository_defaultRoutes = {
3314
3316
  upsert: ()=>({
3315
3317
  path: "/bundles"
@@ -3334,78 +3336,67 @@ var __webpack_exports__ = {};
3334
3336
  ...customRoute?.headers
3335
3337
  }
3336
3338
  });
3337
- const standaloneRepository = (config, hooks)=>(_)=>{
3338
- const routes = {
3339
- upsert: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.upsert(), config.routes?.upsert?.()),
3340
- list: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.list(), config.routes?.list?.()),
3341
- retrieve: (bundleId)=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
3342
- };
3343
- const getHeaders = (routeHeaders)=>({
3344
- "Content-Type": "application/json",
3345
- ...config.commonHeaders,
3346
- ...routeHeaders
3347
- });
3348
- let bundles = [];
3349
- const changedIds = new Set();
3350
- function markChanged(id) {
3351
- changedIds.add(id);
3352
- }
3353
- return {
3354
- name: "standalone-repository",
3355
- async commitBundle () {
3356
- if (0 === changedIds.size) return;
3357
- const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
3358
- if (0 === changedBundles.length) return;
3359
- const { path, headers: routeHeaders } = routes.upsert();
3360
- const response = await fetch(`${config.baseUrl}${path}`, {
3361
- method: "POST",
3362
- headers: getHeaders(routeHeaders),
3363
- body: JSON.stringify(changedBundles)
3364
- });
3365
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3366
- const result = await response.json();
3367
- if (!result.success) throw new Error("Failed to commit bundles");
3368
- changedIds.clear();
3369
- hooks?.onDatabaseUpdated?.();
3370
- },
3371
- async updateBundle (targetBundleId, newBundle) {
3372
- bundles = await this.getBundles();
3373
- const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
3374
- if (-1 === targetIndex) throw new Error("target bundle version not found");
3375
- Object.assign(bundles[targetIndex], newBundle);
3376
- markChanged(targetBundleId);
3377
- },
3378
- async appendBundle (inputBundle) {
3379
- bundles = await this.getBundles();
3380
- bundles.unshift(inputBundle);
3381
- markChanged(inputBundle.id);
3382
- },
3383
- async getBundleById (bundleId) {
3384
- try {
3385
- const { path, headers: routeHeaders } = routes.retrieve(bundleId);
3386
- const response = await fetch(`${config.baseUrl}${path}`, {
3387
- method: "GET",
3388
- headers: getHeaders(routeHeaders)
3389
- });
3390
- if (!response.ok) return null;
3391
- return await response.json();
3392
- } catch (error) {
3393
- return null;
3394
- }
3395
- },
3396
- async getBundles (refresh = false) {
3397
- if (bundles.length > 0 && !refresh) return bundles;
3398
- const { path, headers: routeHeaders } = routes.list();
3339
+ const standaloneRepository = (config, hooks)=>{
3340
+ const routes = {
3341
+ upsert: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.upsert(), config.routes?.upsert?.()),
3342
+ list: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.list(), config.routes?.list?.()),
3343
+ retrieve: (bundleId)=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
3344
+ };
3345
+ const getHeaders = (routeHeaders)=>({
3346
+ "Content-Type": "application/json",
3347
+ ...config.commonHeaders,
3348
+ ...routeHeaders
3349
+ });
3350
+ return (0, plugin_core_namespaceObject.createDatabasePlugin)("standalone-repository", {
3351
+ async getBundleById (bundleId) {
3352
+ try {
3353
+ const { path, headers: routeHeaders } = routes.retrieve(bundleId);
3399
3354
  const response = await fetch(`${config.baseUrl}${path}`, {
3400
3355
  method: "GET",
3401
3356
  headers: getHeaders(routeHeaders)
3402
3357
  });
3403
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3404
- bundles = await response.json();
3405
- return bundles;
3358
+ if (!response.ok) return null;
3359
+ return await response.json();
3360
+ } catch (error) {
3361
+ return null;
3406
3362
  }
3407
- };
3408
- };
3363
+ },
3364
+ async getBundles (options) {
3365
+ const { where, limit, offset = 0 } = options ?? {};
3366
+ const { path, headers: routeHeaders } = routes.list();
3367
+ const response = await fetch(`${config.baseUrl}${path}`, {
3368
+ method: "GET",
3369
+ headers: getHeaders(routeHeaders)
3370
+ });
3371
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3372
+ const bundles = await response.json();
3373
+ let filteredBundles = bundles;
3374
+ if (where?.channel) filteredBundles = filteredBundles.filter((b)=>b.channel === where.channel);
3375
+ if (where?.platform) filteredBundles = filteredBundles.filter((b)=>b.platform === where.platform);
3376
+ if (limit) return filteredBundles.slice(offset, offset + limit);
3377
+ return filteredBundles;
3378
+ },
3379
+ async getChannels () {
3380
+ const allBundles = await this.getBundles();
3381
+ return [
3382
+ ...new Set(allBundles.map((b)=>b.channel))
3383
+ ];
3384
+ },
3385
+ async commitBundle ({ changedSets }) {
3386
+ const changedBundles = changedSets.map((set)=>set.data);
3387
+ if (0 === changedBundles.length) return;
3388
+ const { path, headers: routeHeaders } = routes.upsert();
3389
+ const response = await fetch(`${config.baseUrl}${path}`, {
3390
+ method: "POST",
3391
+ headers: getHeaders(routeHeaders),
3392
+ body: JSON.stringify(changedBundles)
3393
+ });
3394
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3395
+ const result = await response.json();
3396
+ if (!result.success) throw new Error("Failed to commit bundles");
3397
+ }
3398
+ }, hooks);
3399
+ };
3409
3400
  })();
3410
3401
  var __webpack_export_target__ = exports;
3411
3402
  for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
2
2
  import * as __WEBPACK_EXTERNAL_MODULE_fs_promises_400951f8__ from "fs/promises";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__hot_updater_plugin_core_40c1c502__ from "@hot-updater/plugin-core";
3
4
  var __webpack_modules__ = {
4
5
  "../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js": function(module) {
5
6
  function Mime() {
@@ -3276,14 +3277,15 @@ const standaloneStorage = (config, hooks)=>(_)=>{
3276
3277
  throw new Error(error);
3277
3278
  }
3278
3279
  const result = await response.json();
3279
- if (!result.fileUrl) {
3280
- const error = "Failed to upload bundle - no fileUrl in response";
3280
+ if (!result.bucketName || !result.key) {
3281
+ const error = "Failed to upload bundle - no bucketName or key in response";
3281
3282
  console.error(`[uploadBundle] ${error}`);
3282
3283
  throw new Error(error);
3283
3284
  }
3284
3285
  hooks?.onStorageUploaded?.();
3285
3286
  return {
3286
- fileUrl: result.fileUrl
3287
+ bucketName: result.bucketName,
3288
+ key: result.key
3287
3289
  };
3288
3290
  }
3289
3291
  };
@@ -3312,76 +3314,65 @@ const standaloneRepository_createRoute = (defaultRoute, customRoute)=>({
3312
3314
  ...customRoute?.headers
3313
3315
  }
3314
3316
  });
3315
- const standaloneRepository = (config, hooks)=>(_)=>{
3316
- const routes = {
3317
- upsert: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.upsert(), config.routes?.upsert?.()),
3318
- list: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.list(), config.routes?.list?.()),
3319
- retrieve: (bundleId)=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
3320
- };
3321
- const getHeaders = (routeHeaders)=>({
3322
- "Content-Type": "application/json",
3323
- ...config.commonHeaders,
3324
- ...routeHeaders
3325
- });
3326
- let bundles = [];
3327
- const changedIds = new Set();
3328
- function markChanged(id) {
3329
- changedIds.add(id);
3330
- }
3331
- return {
3332
- name: "standalone-repository",
3333
- async commitBundle () {
3334
- if (0 === changedIds.size) return;
3335
- const changedBundles = bundles.filter((b)=>changedIds.has(b.id));
3336
- if (0 === changedBundles.length) return;
3337
- const { path, headers: routeHeaders } = routes.upsert();
3338
- const response = await fetch(`${config.baseUrl}${path}`, {
3339
- method: "POST",
3340
- headers: getHeaders(routeHeaders),
3341
- body: JSON.stringify(changedBundles)
3342
- });
3343
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3344
- const result = await response.json();
3345
- if (!result.success) throw new Error("Failed to commit bundles");
3346
- changedIds.clear();
3347
- hooks?.onDatabaseUpdated?.();
3348
- },
3349
- async updateBundle (targetBundleId, newBundle) {
3350
- bundles = await this.getBundles();
3351
- const targetIndex = bundles.findIndex((u)=>u.id === targetBundleId);
3352
- if (-1 === targetIndex) throw new Error("target bundle version not found");
3353
- Object.assign(bundles[targetIndex], newBundle);
3354
- markChanged(targetBundleId);
3355
- },
3356
- async appendBundle (inputBundle) {
3357
- bundles = await this.getBundles();
3358
- bundles.unshift(inputBundle);
3359
- markChanged(inputBundle.id);
3360
- },
3361
- async getBundleById (bundleId) {
3362
- try {
3363
- const { path, headers: routeHeaders } = routes.retrieve(bundleId);
3364
- const response = await fetch(`${config.baseUrl}${path}`, {
3365
- method: "GET",
3366
- headers: getHeaders(routeHeaders)
3367
- });
3368
- if (!response.ok) return null;
3369
- return await response.json();
3370
- } catch (error) {
3371
- return null;
3372
- }
3373
- },
3374
- async getBundles (refresh = false) {
3375
- if (bundles.length > 0 && !refresh) return bundles;
3376
- const { path, headers: routeHeaders } = routes.list();
3317
+ const standaloneRepository = (config, hooks)=>{
3318
+ const routes = {
3319
+ upsert: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.upsert(), config.routes?.upsert?.()),
3320
+ list: ()=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.list(), config.routes?.list?.()),
3321
+ retrieve: (bundleId)=>standaloneRepository_createRoute(standaloneRepository_defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
3322
+ };
3323
+ const getHeaders = (routeHeaders)=>({
3324
+ "Content-Type": "application/json",
3325
+ ...config.commonHeaders,
3326
+ ...routeHeaders
3327
+ });
3328
+ return (0, __WEBPACK_EXTERNAL_MODULE__hot_updater_plugin_core_40c1c502__.createDatabasePlugin)("standalone-repository", {
3329
+ async getBundleById (bundleId) {
3330
+ try {
3331
+ const { path, headers: routeHeaders } = routes.retrieve(bundleId);
3377
3332
  const response = await fetch(`${config.baseUrl}${path}`, {
3378
3333
  method: "GET",
3379
3334
  headers: getHeaders(routeHeaders)
3380
3335
  });
3381
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3382
- bundles = await response.json();
3383
- return bundles;
3336
+ if (!response.ok) return null;
3337
+ return await response.json();
3338
+ } catch (error) {
3339
+ return null;
3384
3340
  }
3385
- };
3386
- };
3341
+ },
3342
+ async getBundles (options) {
3343
+ const { where, limit, offset = 0 } = options ?? {};
3344
+ const { path, headers: routeHeaders } = routes.list();
3345
+ const response = await fetch(`${config.baseUrl}${path}`, {
3346
+ method: "GET",
3347
+ headers: getHeaders(routeHeaders)
3348
+ });
3349
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3350
+ const bundles = await response.json();
3351
+ let filteredBundles = bundles;
3352
+ if (where?.channel) filteredBundles = filteredBundles.filter((b)=>b.channel === where.channel);
3353
+ if (where?.platform) filteredBundles = filteredBundles.filter((b)=>b.platform === where.platform);
3354
+ if (limit) return filteredBundles.slice(offset, offset + limit);
3355
+ return filteredBundles;
3356
+ },
3357
+ async getChannels () {
3358
+ const allBundles = await this.getBundles();
3359
+ return [
3360
+ ...new Set(allBundles.map((b)=>b.channel))
3361
+ ];
3362
+ },
3363
+ async commitBundle ({ changedSets }) {
3364
+ const changedBundles = changedSets.map((set)=>set.data);
3365
+ if (0 === changedBundles.length) return;
3366
+ const { path, headers: routeHeaders } = routes.upsert();
3367
+ const response = await fetch(`${config.baseUrl}${path}`, {
3368
+ method: "POST",
3369
+ headers: getHeaders(routeHeaders),
3370
+ body: JSON.stringify(changedBundles)
3371
+ });
3372
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
3373
+ const result = await response.json();
3374
+ if (!result.success) throw new Error("Failed to commit bundles");
3375
+ }
3376
+ }, hooks);
3377
+ };
3387
3378
  export { standaloneRepository, standaloneStorage };
@@ -1,4 +1,4 @@
1
- import type { BasePluginArgs, DatabasePlugin, DatabasePluginHooks } from "@hot-updater/plugin-core";
1
+ import type { DatabasePluginHooks } from "@hot-updater/plugin-core";
2
2
  export interface RouteConfig {
3
3
  path: string;
4
4
  headers?: Record<string, string>;
@@ -13,4 +13,4 @@ export interface StandaloneRepositoryConfig {
13
13
  commonHeaders?: Record<string, string>;
14
14
  routes?: Routes;
15
15
  }
16
- export declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: DatabasePluginHooks) => (_: BasePluginArgs) => DatabasePlugin;
16
+ export declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: DatabasePluginHooks) => (options: import("@hot-updater/plugin-core").BasePluginArgs) => import("@hot-updater/plugin-core").DatabasePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/standalone",
3
- "version": "0.12.6",
3
+ "version": "0.13.0",
4
4
  "type": "module",
5
5
  "description": "React Native OTA solution for self-hosted",
6
6
  "sideEffects": false,
@@ -38,8 +38,8 @@
38
38
  "access": "public"
39
39
  },
40
40
  "dependencies": {
41
- "@hot-updater/core": "0.12.6",
42
- "@hot-updater/plugin-core": "0.12.6"
41
+ "@hot-updater/core": "0.13.0",
42
+ "@hot-updater/plugin-core": "0.13.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "mime": "2.6.0",