@hot-updater/standalone 0.20.10 → 0.20.12

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.
Files changed (3) hide show
  1. package/dist/index.cjs +118 -125
  2. package/dist/index.js +116 -123
  3. package/package.json +3 -3
package/dist/index.cjs CHANGED
@@ -24,13 +24,119 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  }) : target, mod));
25
25
 
26
26
  //#endregion
27
- let path = require("path");
28
- path = __toESM(path);
29
- let fs_promises = require("fs/promises");
30
- fs_promises = __toESM(fs_promises);
31
27
  let __hot_updater_plugin_core = require("@hot-updater/plugin-core");
32
28
  __hot_updater_plugin_core = __toESM(__hot_updater_plugin_core);
29
+ let fs_promises = require("fs/promises");
30
+ fs_promises = __toESM(fs_promises);
31
+ let path = require("path");
32
+ path = __toESM(path);
33
+
34
+ //#region src/standaloneRepository.ts
35
+ const defaultRoutes$1 = {
36
+ upsert: () => ({ path: "/bundles" }),
37
+ list: () => ({
38
+ path: "/bundles",
39
+ headers: { "Cache-Control": "no-cache" }
40
+ }),
41
+ retrieve: (bundleId) => ({
42
+ path: `/bundles/${bundleId}`,
43
+ headers: { Accept: "application/json" }
44
+ }),
45
+ delete: (bundleId) => ({ path: `/bundles/${bundleId}` })
46
+ };
47
+ const createRoute$1 = (defaultRoute, customRoute) => ({
48
+ path: customRoute?.path ?? defaultRoute.path,
49
+ headers: {
50
+ ...defaultRoute.headers,
51
+ ...customRoute?.headers
52
+ }
53
+ });
54
+ const standaloneRepository = (config, hooks) => {
55
+ const routes = {
56
+ upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
57
+ list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
58
+ retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
59
+ delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
60
+ };
61
+ const getHeaders = (routeHeaders) => ({
62
+ "Content-Type": "application/json",
63
+ ...config.commonHeaders,
64
+ ...routeHeaders
65
+ });
66
+ return (0, __hot_updater_plugin_core.createDatabasePlugin)("standalone-repository", {
67
+ async getBundleById(_, bundleId) {
68
+ try {
69
+ const { path: path$2, headers: routeHeaders } = routes.retrieve(bundleId);
70
+ const response = await fetch(`${config.baseUrl}${path$2}`, {
71
+ method: "GET",
72
+ headers: getHeaders(routeHeaders)
73
+ });
74
+ if (!response.ok) return null;
75
+ return await response.json();
76
+ } catch {
77
+ return null;
78
+ }
79
+ },
80
+ async getBundles(_, options) {
81
+ const { where, limit, offset = 0 } = options ?? {};
82
+ const { path: path$2, headers: routeHeaders } = routes.list();
83
+ const response = await fetch(`${config.baseUrl}${path$2}`, {
84
+ method: "GET",
85
+ headers: getHeaders(routeHeaders)
86
+ });
87
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
88
+ let filteredBundles = await response.json();
89
+ if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
90
+ if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
91
+ const total = filteredBundles.length;
92
+ return {
93
+ data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
94
+ pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
95
+ limit,
96
+ offset
97
+ })
98
+ };
99
+ },
100
+ async getChannels(_) {
101
+ const result = await this.getBundles(_, {
102
+ limit: 50,
103
+ offset: 0
104
+ });
105
+ return [...new Set(result.data.map((b) => b.channel))];
106
+ },
107
+ async commitBundle(_, { changedSets }) {
108
+ if (changedSets.length === 0) return;
109
+ for (const op of changedSets) if (op.operation === "delete") {
110
+ const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
111
+ const response = await fetch(`${config.baseUrl}${path$2}`, {
112
+ method: "DELETE",
113
+ headers: getHeaders(routeHeaders)
114
+ });
115
+ if (!response.ok) {
116
+ if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
117
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
118
+ }
119
+ if (response.headers.get("content-type")?.includes("application/json")) try {
120
+ await response.json();
121
+ } catch (_jsonError) {
122
+ if (!response.ok) throw new Error("Failed to parse response");
123
+ }
124
+ } else if (op.operation === "insert" || op.operation === "update") {
125
+ const { path: path$2, headers: routeHeaders } = routes.upsert();
126
+ const response = await fetch(`${config.baseUrl}${path$2}`, {
127
+ method: "POST",
128
+ headers: getHeaders(routeHeaders),
129
+ body: JSON.stringify([op.data])
130
+ });
131
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
132
+ if (!(await response.json()).success) throw new Error("Failed to commit bundle");
133
+ }
134
+ hooks?.onDatabaseUpdated?.();
135
+ }
136
+ }, hooks);
137
+ };
33
138
 
139
+ //#endregion
34
140
  //#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
35
141
  var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js": ((exports, module) => {
36
142
  /**
@@ -90,8 +196,7 @@ var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
90
196
  let last = path$2.replace(/^.*[/\\]/, "").toLowerCase();
91
197
  let ext = last.replace(/^.*\./, "").toLowerCase();
92
198
  let hasPath = last.length < path$2.length;
93
- let hasDot = ext.length < last.length - 1;
94
- return (hasDot || !hasPath) && this._types[ext] || null;
199
+ return (ext.length < last.length - 1 || !hasPath) && this._types[ext] || null;
95
200
  };
96
201
  /**
97
202
  * Return file extension associated with a mime type
@@ -1339,11 +1444,11 @@ var require_mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
1339
1444
  //#endregion
1340
1445
  //#region src/standaloneStorage.ts
1341
1446
  var import_mime = /* @__PURE__ */ __toESM(require_mime(), 1);
1342
- const defaultRoutes$1 = {
1343
- uploadBundle: (bundleId, bundlePath) => ({ path: "/uploadBundle" }),
1344
- deleteBundle: (bundleId) => ({ path: "/deleteBundle" })
1447
+ const defaultRoutes = {
1448
+ uploadBundle: (_bundleId, _bundlePath) => ({ path: "/uploadBundle" }),
1449
+ deleteBundle: (_bundleId) => ({ path: "/deleteBundle" })
1345
1450
  };
1346
- const createRoute$1 = (defaultRoute, customRoute) => ({
1451
+ const createRoute = (defaultRoute, customRoute) => ({
1347
1452
  path: customRoute?.path ?? defaultRoute.path,
1348
1453
  headers: {
1349
1454
  ...defaultRoute.headers,
@@ -1352,8 +1457,8 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
1352
1457
  });
1353
1458
  const standaloneStorage = (config, hooks) => (_) => {
1354
1459
  const routes = {
1355
- uploadBundle: (bundleId, bundlePath) => createRoute$1(defaultRoutes$1.uploadBundle(bundleId, bundlePath), config.routes?.uploadBundle?.(bundleId, bundlePath)),
1356
- deleteBundle: (bundleId) => createRoute$1(defaultRoutes$1.deleteBundle(bundleId), config.routes?.deleteBundle?.(bundleId))
1460
+ uploadBundle: (bundleId, bundlePath) => createRoute(defaultRoutes.uploadBundle(bundleId, bundlePath), config.routes?.uploadBundle?.(bundleId, bundlePath)),
1461
+ deleteBundle: (bundleId) => createRoute(defaultRoutes.deleteBundle(bundleId), config.routes?.deleteBundle?.(bundleId))
1357
1462
  };
1358
1463
  const getHeaders = (routeHeaders) => ({
1359
1464
  ...config.commonHeaders,
@@ -1373,8 +1478,7 @@ const standaloneStorage = (config, hooks) => (_) => {
1373
1478
  console.error(error);
1374
1479
  throw error;
1375
1480
  }
1376
- const result = await response.json();
1377
- return { storageUri: result.storageUri };
1481
+ return { storageUri: (await response.json()).storageUri };
1378
1482
  },
1379
1483
  async uploadBundle(bundleId, bundlePath) {
1380
1484
  const fileContent = await fs_promises.default.readFile(bundlePath);
@@ -1406,117 +1510,6 @@ const standaloneStorage = (config, hooks) => (_) => {
1406
1510
  };
1407
1511
  };
1408
1512
 
1409
- //#endregion
1410
- //#region src/standaloneRepository.ts
1411
- const defaultRoutes = {
1412
- upsert: () => ({ path: "/bundles" }),
1413
- list: () => ({
1414
- path: "/bundles",
1415
- headers: { "Cache-Control": "no-cache" }
1416
- }),
1417
- retrieve: (bundleId) => ({
1418
- path: `/bundles/${bundleId}`,
1419
- headers: { Accept: "application/json" }
1420
- }),
1421
- delete: (bundleId) => ({ path: `/bundles/${bundleId}` })
1422
- };
1423
- const createRoute = (defaultRoute, customRoute) => ({
1424
- path: customRoute?.path ?? defaultRoute.path,
1425
- headers: {
1426
- ...defaultRoute.headers,
1427
- ...customRoute?.headers
1428
- }
1429
- });
1430
- const standaloneRepository = (config, hooks) => {
1431
- const routes = {
1432
- upsert: () => createRoute(defaultRoutes.upsert(), config.routes?.upsert?.()),
1433
- list: () => createRoute(defaultRoutes.list(), config.routes?.list?.()),
1434
- retrieve: (bundleId) => createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
1435
- delete: (bundleId) => createRoute(defaultRoutes.delete(bundleId), config.routes?.delete?.(bundleId))
1436
- };
1437
- const getHeaders = (routeHeaders) => ({
1438
- "Content-Type": "application/json",
1439
- ...config.commonHeaders,
1440
- ...routeHeaders
1441
- });
1442
- return (0, __hot_updater_plugin_core.createDatabasePlugin)("standalone-repository", {
1443
- async getBundleById(_, bundleId) {
1444
- try {
1445
- const { path: path$2, headers: routeHeaders } = routes.retrieve(bundleId);
1446
- const response = await fetch(`${config.baseUrl}${path$2}`, {
1447
- method: "GET",
1448
- headers: getHeaders(routeHeaders)
1449
- });
1450
- if (!response.ok) return null;
1451
- return await response.json();
1452
- } catch (error) {
1453
- return null;
1454
- }
1455
- },
1456
- async getBundles(_, options) {
1457
- const { where, limit, offset = 0 } = options ?? {};
1458
- const { path: path$2, headers: routeHeaders } = routes.list();
1459
- const response = await fetch(`${config.baseUrl}${path$2}`, {
1460
- method: "GET",
1461
- headers: getHeaders(routeHeaders)
1462
- });
1463
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
1464
- const bundles = await response.json();
1465
- let filteredBundles = bundles;
1466
- if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
1467
- if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
1468
- const total = filteredBundles.length;
1469
- const data = limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles;
1470
- const pagination = (0, __hot_updater_plugin_core.calculatePagination)(total, {
1471
- limit,
1472
- offset
1473
- });
1474
- return {
1475
- data,
1476
- pagination
1477
- };
1478
- },
1479
- async getChannels(_) {
1480
- const result = await this.getBundles(_, {
1481
- limit: 50,
1482
- offset: 0
1483
- });
1484
- return [...new Set(result.data.map((b) => b.channel))];
1485
- },
1486
- async commitBundle(_, { changedSets }) {
1487
- if (changedSets.length === 0) return;
1488
- for (const op of changedSets) if (op.operation === "delete") {
1489
- const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
1490
- const response = await fetch(`${config.baseUrl}${path$2}`, {
1491
- method: "DELETE",
1492
- headers: getHeaders(routeHeaders)
1493
- });
1494
- if (!response.ok) {
1495
- if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
1496
- throw new Error(`API Error: ${response.status} ${response.statusText}`);
1497
- }
1498
- const contentType = response.headers.get("content-type");
1499
- if (contentType?.includes("application/json")) try {
1500
- await response.json();
1501
- } catch (jsonError) {
1502
- if (!response.ok) throw new Error("Failed to parse response");
1503
- }
1504
- } else if (op.operation === "insert" || op.operation === "update") {
1505
- const { path: path$2, headers: routeHeaders } = routes.upsert();
1506
- const response = await fetch(`${config.baseUrl}${path$2}`, {
1507
- method: "POST",
1508
- headers: getHeaders(routeHeaders),
1509
- body: JSON.stringify([op.data])
1510
- });
1511
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
1512
- const result = await response.json();
1513
- if (!result.success) throw new Error("Failed to commit bundle");
1514
- }
1515
- hooks?.onDatabaseUpdated?.();
1516
- }
1517
- }, hooks);
1518
- };
1519
-
1520
1513
  //#endregion
1521
1514
  exports.standaloneRepository = standaloneRepository;
1522
1515
  exports.standaloneStorage = standaloneStorage;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import path from "path";
2
- import fs from "fs/promises";
3
1
  import { calculatePagination, createDatabasePlugin } from "@hot-updater/plugin-core";
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
4
 
5
5
  //#region rolldown:runtime
6
6
  var __create = Object.create;
@@ -27,6 +27,112 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  enumerable: true
28
28
  }) : target, mod));
29
29
 
30
+ //#endregion
31
+ //#region src/standaloneRepository.ts
32
+ const defaultRoutes$1 = {
33
+ upsert: () => ({ path: "/bundles" }),
34
+ list: () => ({
35
+ path: "/bundles",
36
+ headers: { "Cache-Control": "no-cache" }
37
+ }),
38
+ retrieve: (bundleId) => ({
39
+ path: `/bundles/${bundleId}`,
40
+ headers: { Accept: "application/json" }
41
+ }),
42
+ delete: (bundleId) => ({ path: `/bundles/${bundleId}` })
43
+ };
44
+ const createRoute$1 = (defaultRoute, customRoute) => ({
45
+ path: customRoute?.path ?? defaultRoute.path,
46
+ headers: {
47
+ ...defaultRoute.headers,
48
+ ...customRoute?.headers
49
+ }
50
+ });
51
+ const standaloneRepository = (config, hooks) => {
52
+ const routes = {
53
+ upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
54
+ list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
55
+ retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
56
+ delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
57
+ };
58
+ const getHeaders = (routeHeaders) => ({
59
+ "Content-Type": "application/json",
60
+ ...config.commonHeaders,
61
+ ...routeHeaders
62
+ });
63
+ return createDatabasePlugin("standalone-repository", {
64
+ async getBundleById(_, bundleId) {
65
+ try {
66
+ const { path: path$1, headers: routeHeaders } = routes.retrieve(bundleId);
67
+ const response = await fetch(`${config.baseUrl}${path$1}`, {
68
+ method: "GET",
69
+ headers: getHeaders(routeHeaders)
70
+ });
71
+ if (!response.ok) return null;
72
+ return await response.json();
73
+ } catch {
74
+ return null;
75
+ }
76
+ },
77
+ async getBundles(_, options) {
78
+ const { where, limit, offset = 0 } = options ?? {};
79
+ const { path: path$1, headers: routeHeaders } = routes.list();
80
+ const response = await fetch(`${config.baseUrl}${path$1}`, {
81
+ method: "GET",
82
+ headers: getHeaders(routeHeaders)
83
+ });
84
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
85
+ let filteredBundles = await response.json();
86
+ if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
87
+ if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
88
+ const total = filteredBundles.length;
89
+ return {
90
+ data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
91
+ pagination: calculatePagination(total, {
92
+ limit,
93
+ offset
94
+ })
95
+ };
96
+ },
97
+ async getChannels(_) {
98
+ const result = await this.getBundles(_, {
99
+ limit: 50,
100
+ offset: 0
101
+ });
102
+ return [...new Set(result.data.map((b) => b.channel))];
103
+ },
104
+ async commitBundle(_, { changedSets }) {
105
+ if (changedSets.length === 0) return;
106
+ for (const op of changedSets) if (op.operation === "delete") {
107
+ const { path: path$1, headers: routeHeaders } = routes.delete(op.data.id);
108
+ const response = await fetch(`${config.baseUrl}${path$1}`, {
109
+ method: "DELETE",
110
+ headers: getHeaders(routeHeaders)
111
+ });
112
+ if (!response.ok) {
113
+ if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
114
+ throw new Error(`API Error: ${response.status} ${response.statusText}`);
115
+ }
116
+ if (response.headers.get("content-type")?.includes("application/json")) try {
117
+ await response.json();
118
+ } catch (_jsonError) {
119
+ if (!response.ok) throw new Error("Failed to parse response");
120
+ }
121
+ } else if (op.operation === "insert" || op.operation === "update") {
122
+ const { path: path$1, headers: routeHeaders } = routes.upsert();
123
+ const response = await fetch(`${config.baseUrl}${path$1}`, {
124
+ method: "POST",
125
+ headers: getHeaders(routeHeaders),
126
+ body: JSON.stringify([op.data])
127
+ });
128
+ if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
129
+ if (!(await response.json()).success) throw new Error("Failed to commit bundle");
130
+ }
131
+ hooks?.onDatabaseUpdated?.();
132
+ }
133
+ }, hooks);
134
+ };
135
+
30
136
  //#endregion
31
137
  //#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
32
138
  var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js": ((exports, module) => {
@@ -87,8 +193,7 @@ var require_Mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
87
193
  let last = path$1.replace(/^.*[/\\]/, "").toLowerCase();
88
194
  let ext = last.replace(/^.*\./, "").toLowerCase();
89
195
  let hasPath = last.length < path$1.length;
90
- let hasDot = ext.length < last.length - 1;
91
- return (hasDot || !hasPath) && this._types[ext] || null;
196
+ return (ext.length < last.length - 1 || !hasPath) && this._types[ext] || null;
92
197
  };
93
198
  /**
94
199
  * Return file extension associated with a mime type
@@ -1336,11 +1441,11 @@ var require_mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
1336
1441
  //#endregion
1337
1442
  //#region src/standaloneStorage.ts
1338
1443
  var import_mime = /* @__PURE__ */ __toESM(require_mime(), 1);
1339
- const defaultRoutes$1 = {
1340
- uploadBundle: (bundleId, bundlePath) => ({ path: "/uploadBundle" }),
1341
- deleteBundle: (bundleId) => ({ path: "/deleteBundle" })
1444
+ const defaultRoutes = {
1445
+ uploadBundle: (_bundleId, _bundlePath) => ({ path: "/uploadBundle" }),
1446
+ deleteBundle: (_bundleId) => ({ path: "/deleteBundle" })
1342
1447
  };
1343
- const createRoute$1 = (defaultRoute, customRoute) => ({
1448
+ const createRoute = (defaultRoute, customRoute) => ({
1344
1449
  path: customRoute?.path ?? defaultRoute.path,
1345
1450
  headers: {
1346
1451
  ...defaultRoute.headers,
@@ -1349,8 +1454,8 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
1349
1454
  });
1350
1455
  const standaloneStorage = (config, hooks) => (_) => {
1351
1456
  const routes = {
1352
- uploadBundle: (bundleId, bundlePath) => createRoute$1(defaultRoutes$1.uploadBundle(bundleId, bundlePath), config.routes?.uploadBundle?.(bundleId, bundlePath)),
1353
- deleteBundle: (bundleId) => createRoute$1(defaultRoutes$1.deleteBundle(bundleId), config.routes?.deleteBundle?.(bundleId))
1457
+ uploadBundle: (bundleId, bundlePath) => createRoute(defaultRoutes.uploadBundle(bundleId, bundlePath), config.routes?.uploadBundle?.(bundleId, bundlePath)),
1458
+ deleteBundle: (bundleId) => createRoute(defaultRoutes.deleteBundle(bundleId), config.routes?.deleteBundle?.(bundleId))
1354
1459
  };
1355
1460
  const getHeaders = (routeHeaders) => ({
1356
1461
  ...config.commonHeaders,
@@ -1370,8 +1475,7 @@ const standaloneStorage = (config, hooks) => (_) => {
1370
1475
  console.error(error);
1371
1476
  throw error;
1372
1477
  }
1373
- const result = await response.json();
1374
- return { storageUri: result.storageUri };
1478
+ return { storageUri: (await response.json()).storageUri };
1375
1479
  },
1376
1480
  async uploadBundle(bundleId, bundlePath) {
1377
1481
  const fileContent = await fs.readFile(bundlePath);
@@ -1403,116 +1507,5 @@ const standaloneStorage = (config, hooks) => (_) => {
1403
1507
  };
1404
1508
  };
1405
1509
 
1406
- //#endregion
1407
- //#region src/standaloneRepository.ts
1408
- const defaultRoutes = {
1409
- upsert: () => ({ path: "/bundles" }),
1410
- list: () => ({
1411
- path: "/bundles",
1412
- headers: { "Cache-Control": "no-cache" }
1413
- }),
1414
- retrieve: (bundleId) => ({
1415
- path: `/bundles/${bundleId}`,
1416
- headers: { Accept: "application/json" }
1417
- }),
1418
- delete: (bundleId) => ({ path: `/bundles/${bundleId}` })
1419
- };
1420
- const createRoute = (defaultRoute, customRoute) => ({
1421
- path: customRoute?.path ?? defaultRoute.path,
1422
- headers: {
1423
- ...defaultRoute.headers,
1424
- ...customRoute?.headers
1425
- }
1426
- });
1427
- const standaloneRepository = (config, hooks) => {
1428
- const routes = {
1429
- upsert: () => createRoute(defaultRoutes.upsert(), config.routes?.upsert?.()),
1430
- list: () => createRoute(defaultRoutes.list(), config.routes?.list?.()),
1431
- retrieve: (bundleId) => createRoute(defaultRoutes.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
1432
- delete: (bundleId) => createRoute(defaultRoutes.delete(bundleId), config.routes?.delete?.(bundleId))
1433
- };
1434
- const getHeaders = (routeHeaders) => ({
1435
- "Content-Type": "application/json",
1436
- ...config.commonHeaders,
1437
- ...routeHeaders
1438
- });
1439
- return createDatabasePlugin("standalone-repository", {
1440
- async getBundleById(_, bundleId) {
1441
- try {
1442
- const { path: path$1, headers: routeHeaders } = routes.retrieve(bundleId);
1443
- const response = await fetch(`${config.baseUrl}${path$1}`, {
1444
- method: "GET",
1445
- headers: getHeaders(routeHeaders)
1446
- });
1447
- if (!response.ok) return null;
1448
- return await response.json();
1449
- } catch (error) {
1450
- return null;
1451
- }
1452
- },
1453
- async getBundles(_, options) {
1454
- const { where, limit, offset = 0 } = options ?? {};
1455
- const { path: path$1, headers: routeHeaders } = routes.list();
1456
- const response = await fetch(`${config.baseUrl}${path$1}`, {
1457
- method: "GET",
1458
- headers: getHeaders(routeHeaders)
1459
- });
1460
- if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
1461
- const bundles = await response.json();
1462
- let filteredBundles = bundles;
1463
- if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
1464
- if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
1465
- const total = filteredBundles.length;
1466
- const data = limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles;
1467
- const pagination = calculatePagination(total, {
1468
- limit,
1469
- offset
1470
- });
1471
- return {
1472
- data,
1473
- pagination
1474
- };
1475
- },
1476
- async getChannels(_) {
1477
- const result = await this.getBundles(_, {
1478
- limit: 50,
1479
- offset: 0
1480
- });
1481
- return [...new Set(result.data.map((b) => b.channel))];
1482
- },
1483
- async commitBundle(_, { changedSets }) {
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?.();
1513
- }
1514
- }, hooks);
1515
- };
1516
-
1517
1510
  //#endregion
1518
1511
  export { standaloneRepository, standaloneStorage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/standalone",
3
- "version": "0.20.10",
3
+ "version": "0.20.12",
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.20.10",
42
- "@hot-updater/plugin-core": "0.20.10"
41
+ "@hot-updater/core": "0.20.12",
42
+ "@hot-updater/plugin-core": "0.20.12"
43
43
  },
44
44
  "devDependencies": {
45
45
  "mime": "2.6.0",