@hot-updater/standalone 0.18.3 → 0.18.5

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
@@ -1361,7 +1361,7 @@ const standaloneStorage = (config, hooks) => (_) => {
1361
1361
  async deleteBundle(bundleId) {
1362
1362
  const { path: routePath, headers: routeHeaders } = routes.deleteBundle(bundleId);
1363
1363
  const response = await fetch(`${config.baseUrl}${routePath}`, {
1364
- method: "POST",
1364
+ method: "DELETE",
1365
1365
  headers: getHeaders(routeHeaders),
1366
1366
  body: JSON.stringify({ bundleId })
1367
1367
  });
@@ -1370,7 +1370,8 @@ const standaloneStorage = (config, hooks) => (_) => {
1370
1370
  console.error(error);
1371
1371
  throw error;
1372
1372
  }
1373
- return bundleId;
1373
+ const result = await response.json();
1374
+ return { storageUri: result.storageUri };
1374
1375
  },
1375
1376
  async uploadBundle(bundleId, bundlePath) {
1376
1377
  const fileContent = await fs_promises.default.readFile(bundlePath);
@@ -1413,7 +1414,8 @@ const defaultRoutes = {
1413
1414
  retrieve: (bundleId) => ({
1414
1415
  path: `/bundles/${bundleId}`,
1415
1416
  headers: { Accept: "application/json" }
1416
- })
1417
+ }),
1418
+ delete: (bundleId) => ({ path: `/bundles/${bundleId}` })
1417
1419
  };
1418
1420
  const createRoute = (defaultRoute, customRoute) => ({
1419
1421
  path: customRoute?.path ?? defaultRoute.path,
@@ -1426,7 +1428,8 @@ const standaloneRepository = (config, hooks) => {
1426
1428
  const routes = {
1427
1429
  upsert: () => createRoute(defaultRoutes.upsert(), config.routes?.upsert?.()),
1428
1430
  list: () => createRoute(defaultRoutes.list(), config.routes?.list?.()),
1429
- retrieve: (bundleId) => createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
1431
+ retrieve: (bundleId) => createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
1432
+ delete: (bundleId) => createRoute(defaultRoutes.delete(bundleId), config.routes?.delete?.(bundleId))
1430
1433
  };
1431
1434
  const getHeaders = (routeHeaders) => ({
1432
1435
  "Content-Type": "application/json",
@@ -1478,17 +1481,35 @@ const standaloneRepository = (config, hooks) => {
1478
1481
  return [...new Set(result.data.map((b) => b.channel))];
1479
1482
  },
1480
1483
  async commitBundle(_, { changedSets }) {
1481
- const changedBundles = changedSets.map((set) => set.data);
1482
- if (changedBundles.length === 0) return;
1483
- const { path: path$2, headers: routeHeaders } = routes.upsert();
1484
- const response = await fetch(`${config.baseUrl}${path$2}`, {
1485
- method: "POST",
1486
- headers: getHeaders(routeHeaders),
1487
- body: JSON.stringify(changedBundles)
1488
- });
1489
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
1490
- const result = await response.json();
1491
- if (!result.success) throw new Error("Failed to commit bundles");
1484
+ if (changedSets.length === 0) return;
1485
+ for (const op of changedSets) if (op.operation === "delete") {
1486
+ const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
1487
+ const response = await fetch(`${config.baseUrl}${path$2}`, {
1488
+ method: "DELETE",
1489
+ headers: getHeaders(routeHeaders)
1490
+ });
1491
+ if (!response.ok) {
1492
+ if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
1493
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
1494
+ }
1495
+ const contentType = response.headers.get("content-type");
1496
+ if (contentType?.includes("application/json")) try {
1497
+ await response.json();
1498
+ } catch (jsonError) {
1499
+ if (!response.ok) throw new Error("Failed to parse response");
1500
+ }
1501
+ } else if (op.operation === "insert" || op.operation === "update") {
1502
+ const { path: path$2, headers: routeHeaders } = routes.upsert();
1503
+ const response = await fetch(`${config.baseUrl}${path$2}`, {
1504
+ method: "POST",
1505
+ headers: getHeaders(routeHeaders),
1506
+ body: JSON.stringify([op.data])
1507
+ });
1508
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
1509
+ const result = await response.json();
1510
+ if (!result.success) throw new Error("Failed to commit bundle");
1511
+ }
1512
+ hooks?.onDatabaseUpdated?.();
1492
1513
  }
1493
1514
  }, hooks);
1494
1515
  };
package/dist/index.d.cts CHANGED
@@ -10,6 +10,7 @@ interface Routes {
10
10
  upsert: () => RouteConfig;
11
11
  list: () => RouteConfig;
12
12
  retrieve: (bundleId: string) => RouteConfig;
13
+ delete: (bundleId: string) => RouteConfig;
13
14
  }
14
15
  interface StandaloneRepositoryConfig {
15
16
  baseUrl: string;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ interface Routes {
10
10
  upsert: () => RouteConfig;
11
11
  list: () => RouteConfig;
12
12
  retrieve: (bundleId: string) => RouteConfig;
13
+ delete: (bundleId: string) => RouteConfig;
13
14
  }
14
15
  interface StandaloneRepositoryConfig {
15
16
  baseUrl: string;
package/dist/index.js CHANGED
@@ -1361,7 +1361,7 @@ const standaloneStorage = (config, hooks) => (_) => {
1361
1361
  async deleteBundle(bundleId) {
1362
1362
  const { path: routePath, headers: routeHeaders } = routes.deleteBundle(bundleId);
1363
1363
  const response = await fetch(`${config.baseUrl}${routePath}`, {
1364
- method: "POST",
1364
+ method: "DELETE",
1365
1365
  headers: getHeaders(routeHeaders),
1366
1366
  body: JSON.stringify({ bundleId })
1367
1367
  });
@@ -1370,7 +1370,8 @@ const standaloneStorage = (config, hooks) => (_) => {
1370
1370
  console.error(error);
1371
1371
  throw error;
1372
1372
  }
1373
- return bundleId;
1373
+ const result = await response.json();
1374
+ return { storageUri: result.storageUri };
1374
1375
  },
1375
1376
  async uploadBundle(bundleId, bundlePath) {
1376
1377
  const fileContent = await fs.readFile(bundlePath);
@@ -1413,7 +1414,8 @@ const defaultRoutes = {
1413
1414
  retrieve: (bundleId) => ({
1414
1415
  path: `/bundles/${bundleId}`,
1415
1416
  headers: { Accept: "application/json" }
1416
- })
1417
+ }),
1418
+ delete: (bundleId) => ({ path: `/bundles/${bundleId}` })
1417
1419
  };
1418
1420
  const createRoute = (defaultRoute, customRoute) => ({
1419
1421
  path: customRoute?.path ?? defaultRoute.path,
@@ -1426,7 +1428,8 @@ const standaloneRepository = (config, hooks) => {
1426
1428
  const routes = {
1427
1429
  upsert: () => createRoute(defaultRoutes.upsert(), config.routes?.upsert?.()),
1428
1430
  list: () => createRoute(defaultRoutes.list(), config.routes?.list?.()),
1429
- retrieve: (bundleId) => createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId))
1431
+ retrieve: (bundleId) => createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
1432
+ delete: (bundleId) => createRoute(defaultRoutes.delete(bundleId), config.routes?.delete?.(bundleId))
1430
1433
  };
1431
1434
  const getHeaders = (routeHeaders) => ({
1432
1435
  "Content-Type": "application/json",
@@ -1478,17 +1481,35 @@ const standaloneRepository = (config, hooks) => {
1478
1481
  return [...new Set(result.data.map((b) => b.channel))];
1479
1482
  },
1480
1483
  async commitBundle(_, { changedSets }) {
1481
- const changedBundles = changedSets.map((set) => set.data);
1482
- if (changedBundles.length === 0) return;
1483
- const { path: path$1, headers: routeHeaders } = routes.upsert();
1484
- const response = await fetch(`${config.baseUrl}${path$1}`, {
1485
- method: "POST",
1486
- headers: getHeaders(routeHeaders),
1487
- body: JSON.stringify(changedBundles)
1488
- });
1489
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
1490
- const result = await response.json();
1491
- if (!result.success) throw new Error("Failed to commit bundles");
1484
+ if (changedSets.length === 0) return;
1485
+ for (const op of changedSets) if (op.operation === "delete") {
1486
+ const { path: path$1, headers: routeHeaders } = routes.delete(op.data.id);
1487
+ const response = await fetch(`${config.baseUrl}${path$1}`, {
1488
+ method: "DELETE",
1489
+ headers: getHeaders(routeHeaders)
1490
+ });
1491
+ if (!response.ok) {
1492
+ if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
1493
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
1494
+ }
1495
+ const contentType = response.headers.get("content-type");
1496
+ if (contentType?.includes("application/json")) try {
1497
+ await response.json();
1498
+ } catch (jsonError) {
1499
+ if (!response.ok) throw new Error("Failed to parse response");
1500
+ }
1501
+ } else if (op.operation === "insert" || op.operation === "update") {
1502
+ const { path: path$1, headers: routeHeaders } = routes.upsert();
1503
+ const response = await fetch(`${config.baseUrl}${path$1}`, {
1504
+ method: "POST",
1505
+ headers: getHeaders(routeHeaders),
1506
+ body: JSON.stringify([op.data])
1507
+ });
1508
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
1509
+ const result = await response.json();
1510
+ if (!result.success) throw new Error("Failed to commit bundle");
1511
+ }
1512
+ hooks?.onDatabaseUpdated?.();
1492
1513
  }
1493
1514
  }, hooks);
1494
1515
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/standalone",
3
- "version": "0.18.3",
3
+ "version": "0.18.5",
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.18.3",
42
- "@hot-updater/plugin-core": "0.18.3"
41
+ "@hot-updater/core": "0.18.5",
42
+ "@hot-updater/plugin-core": "0.18.5"
43
43
  },
44
44
  "devDependencies": {
45
45
  "mime": "2.6.0",