@hot-updater/standalone 0.20.14 → 0.21.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 +37 -20
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +37 -20
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -58,6 +58,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
58
58
|
retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
|
|
59
59
|
delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
|
|
60
60
|
};
|
|
61
|
+
const buildUrl = (path$2) => `${config.baseUrl}${path$2}`;
|
|
61
62
|
const getHeaders = (routeHeaders) => ({
|
|
62
63
|
"Content-Type": "application/json",
|
|
63
64
|
...config.commonHeaders,
|
|
@@ -67,7 +68,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
67
68
|
async getBundleById(_, bundleId) {
|
|
68
69
|
try {
|
|
69
70
|
const { path: path$2, headers: routeHeaders } = routes.retrieve(bundleId);
|
|
70
|
-
const response = await fetch(
|
|
71
|
+
const response = await fetch(buildUrl(path$2), {
|
|
71
72
|
method: "GET",
|
|
72
73
|
headers: getHeaders(routeHeaders)
|
|
73
74
|
});
|
|
@@ -80,7 +81,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
80
81
|
async getBundles(_, options) {
|
|
81
82
|
const { where, limit, offset = 0 } = options ?? {};
|
|
82
83
|
const { path: path$2, headers: routeHeaders } = routes.list();
|
|
83
|
-
const response = await fetch(
|
|
84
|
+
const response = await fetch(buildUrl(path$2), {
|
|
84
85
|
method: "GET",
|
|
85
86
|
headers: getHeaders(routeHeaders)
|
|
86
87
|
});
|
|
@@ -108,7 +109,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
108
109
|
if (changedSets.length === 0) return;
|
|
109
110
|
for (const op of changedSets) if (op.operation === "delete") {
|
|
110
111
|
const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
|
|
111
|
-
const response = await fetch(
|
|
112
|
+
const response = await fetch(buildUrl(path$2), {
|
|
112
113
|
method: "DELETE",
|
|
113
114
|
headers: getHeaders(routeHeaders)
|
|
114
115
|
});
|
|
@@ -123,7 +124,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
123
124
|
}
|
|
124
125
|
} else if (op.operation === "insert" || op.operation === "update") {
|
|
125
126
|
const { path: path$2, headers: routeHeaders } = routes.upsert();
|
|
126
|
-
const response = await fetch(
|
|
127
|
+
const response = await fetch(buildUrl(path$2), {
|
|
127
128
|
method: "POST",
|
|
128
129
|
headers: getHeaders(routeHeaders),
|
|
129
130
|
body: JSON.stringify([op.data])
|
|
@@ -1445,8 +1446,9 @@ var require_mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
|
|
|
1445
1446
|
//#region src/standaloneStorage.ts
|
|
1446
1447
|
var import_mime = /* @__PURE__ */ __toESM(require_mime(), 1);
|
|
1447
1448
|
const defaultRoutes = {
|
|
1448
|
-
|
|
1449
|
-
|
|
1449
|
+
upload: (_key, _filePath) => ({ path: "/upload" }),
|
|
1450
|
+
delete: (_storageUri) => ({ path: "/delete" }),
|
|
1451
|
+
getDownloadUrl: (_storageUri) => ({ path: "/getDownloadUrl" })
|
|
1450
1452
|
};
|
|
1451
1453
|
const createRoute = (defaultRoute, customRoute) => ({
|
|
1452
1454
|
path: customRoute?.path ?? defaultRoute.path,
|
|
@@ -1457,8 +1459,9 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
1457
1459
|
});
|
|
1458
1460
|
const standaloneStorage = (config, hooks) => (_) => {
|
|
1459
1461
|
const routes = {
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
+
upload: (key, filePath) => createRoute(defaultRoutes.upload(key, filePath), config.routes?.upload?.(key, filePath)),
|
|
1463
|
+
delete: (storageUri) => createRoute(defaultRoutes.delete(storageUri), config.routes?.delete?.(storageUri)),
|
|
1464
|
+
getDownloadUrl: (storageUri) => createRoute(defaultRoutes.getDownloadUrl(storageUri), config.routes?.getDownloadUrl?.(storageUri))
|
|
1462
1465
|
};
|
|
1463
1466
|
const getHeaders = (routeHeaders) => ({
|
|
1464
1467
|
...config.commonHeaders,
|
|
@@ -1466,28 +1469,28 @@ const standaloneStorage = (config, hooks) => (_) => {
|
|
|
1466
1469
|
});
|
|
1467
1470
|
return {
|
|
1468
1471
|
name: "standaloneStorage",
|
|
1469
|
-
|
|
1470
|
-
|
|
1472
|
+
supportedProtocol: "http",
|
|
1473
|
+
async delete(storageUri) {
|
|
1474
|
+
const { path: routePath, headers: routeHeaders } = routes.delete(storageUri);
|
|
1471
1475
|
const response = await fetch(`${config.baseUrl}${routePath}`, {
|
|
1472
1476
|
method: "DELETE",
|
|
1473
1477
|
headers: getHeaders(routeHeaders),
|
|
1474
|
-
body: JSON.stringify({
|
|
1478
|
+
body: JSON.stringify({ storageUri })
|
|
1475
1479
|
});
|
|
1476
1480
|
if (!response.ok) {
|
|
1477
1481
|
const error = /* @__PURE__ */ new Error(`Failed to delete bundle: ${response.statusText}`);
|
|
1478
1482
|
console.error(error);
|
|
1479
1483
|
throw error;
|
|
1480
1484
|
}
|
|
1481
|
-
return { storageUri: (await response.json()).storageUri };
|
|
1482
1485
|
},
|
|
1483
|
-
async
|
|
1484
|
-
const fileContent = await fs_promises.default.readFile(
|
|
1485
|
-
const contentType = import_mime.default.getType(
|
|
1486
|
-
const filename = path.default.basename(
|
|
1487
|
-
const { path: routePath, headers: routeHeaders } = routes.
|
|
1486
|
+
async upload(key, filePath) {
|
|
1487
|
+
const fileContent = await fs_promises.default.readFile(filePath);
|
|
1488
|
+
const contentType = import_mime.default.getType(filePath) ?? "application/octet-stream";
|
|
1489
|
+
const filename = path.default.basename(filePath);
|
|
1490
|
+
const { path: routePath, headers: routeHeaders } = routes.upload(key, filePath);
|
|
1488
1491
|
const formData = new FormData();
|
|
1489
1492
|
formData.append("file", new Blob([fileContent], { type: contentType }), filename);
|
|
1490
|
-
formData.append("
|
|
1493
|
+
formData.append("key", key);
|
|
1491
1494
|
const response = await fetch(`${config.baseUrl}${routePath}`, {
|
|
1492
1495
|
method: "POST",
|
|
1493
1496
|
headers: getHeaders(routeHeaders),
|
|
@@ -1495,17 +1498,31 @@ const standaloneStorage = (config, hooks) => (_) => {
|
|
|
1495
1498
|
});
|
|
1496
1499
|
if (!response.ok) {
|
|
1497
1500
|
const error = `Failed to upload bundle: ${response.statusText}`;
|
|
1498
|
-
console.error(`[
|
|
1501
|
+
console.error(`[upload] ${error}`);
|
|
1499
1502
|
throw new Error(error);
|
|
1500
1503
|
}
|
|
1501
1504
|
const result = await response.json();
|
|
1502
1505
|
if (!result.storageUri) {
|
|
1503
1506
|
const error = "Failed to upload bundle - no storageUri in response";
|
|
1504
|
-
console.error(`[
|
|
1507
|
+
console.error(`[upload] ${error}`);
|
|
1505
1508
|
throw new Error(error);
|
|
1506
1509
|
}
|
|
1507
1510
|
hooks?.onStorageUploaded?.();
|
|
1508
1511
|
return { storageUri: result.storageUri };
|
|
1512
|
+
},
|
|
1513
|
+
async getDownloadUrl(storageUri) {
|
|
1514
|
+
const { path: routePath, headers: routeHeaders } = routes.getDownloadUrl(storageUri);
|
|
1515
|
+
const response = await fetch(`${config.baseUrl}${routePath}`, {
|
|
1516
|
+
method: "POST",
|
|
1517
|
+
headers: getHeaders(routeHeaders),
|
|
1518
|
+
body: JSON.stringify({ storageUri })
|
|
1519
|
+
});
|
|
1520
|
+
if (!response.ok) {
|
|
1521
|
+
const error = /* @__PURE__ */ new Error(`Failed to get download URL: ${response.statusText}`);
|
|
1522
|
+
console.error(error);
|
|
1523
|
+
throw error;
|
|
1524
|
+
}
|
|
1525
|
+
return { fileUrl: (await response.json()).fileUrl };
|
|
1509
1526
|
}
|
|
1510
1527
|
};
|
|
1511
1528
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -21,8 +21,9 @@ declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?:
|
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/standaloneStorage.d.ts
|
|
23
23
|
interface StorageRoutes {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
upload: (key: string, filePath: string) => RouteConfig;
|
|
25
|
+
delete: (storageUri: string) => RouteConfig;
|
|
26
|
+
getDownloadUrl: (storageUri: string) => RouteConfig;
|
|
26
27
|
}
|
|
27
28
|
interface StandaloneStorageConfig {
|
|
28
29
|
baseUrl: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,8 +21,9 @@ declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?:
|
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/standaloneStorage.d.ts
|
|
23
23
|
interface StorageRoutes {
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
upload: (key: string, filePath: string) => RouteConfig;
|
|
25
|
+
delete: (storageUri: string) => RouteConfig;
|
|
26
|
+
getDownloadUrl: (storageUri: string) => RouteConfig;
|
|
26
27
|
}
|
|
27
28
|
interface StandaloneStorageConfig {
|
|
28
29
|
baseUrl: string;
|
package/dist/index.js
CHANGED
|
@@ -55,6 +55,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
55
55
|
retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
|
|
56
56
|
delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
|
|
57
57
|
};
|
|
58
|
+
const buildUrl = (path$1) => `${config.baseUrl}${path$1}`;
|
|
58
59
|
const getHeaders = (routeHeaders) => ({
|
|
59
60
|
"Content-Type": "application/json",
|
|
60
61
|
...config.commonHeaders,
|
|
@@ -64,7 +65,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
64
65
|
async getBundleById(_, bundleId) {
|
|
65
66
|
try {
|
|
66
67
|
const { path: path$1, headers: routeHeaders } = routes.retrieve(bundleId);
|
|
67
|
-
const response = await fetch(
|
|
68
|
+
const response = await fetch(buildUrl(path$1), {
|
|
68
69
|
method: "GET",
|
|
69
70
|
headers: getHeaders(routeHeaders)
|
|
70
71
|
});
|
|
@@ -77,7 +78,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
77
78
|
async getBundles(_, options) {
|
|
78
79
|
const { where, limit, offset = 0 } = options ?? {};
|
|
79
80
|
const { path: path$1, headers: routeHeaders } = routes.list();
|
|
80
|
-
const response = await fetch(
|
|
81
|
+
const response = await fetch(buildUrl(path$1), {
|
|
81
82
|
method: "GET",
|
|
82
83
|
headers: getHeaders(routeHeaders)
|
|
83
84
|
});
|
|
@@ -105,7 +106,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
105
106
|
if (changedSets.length === 0) return;
|
|
106
107
|
for (const op of changedSets) if (op.operation === "delete") {
|
|
107
108
|
const { path: path$1, headers: routeHeaders } = routes.delete(op.data.id);
|
|
108
|
-
const response = await fetch(
|
|
109
|
+
const response = await fetch(buildUrl(path$1), {
|
|
109
110
|
method: "DELETE",
|
|
110
111
|
headers: getHeaders(routeHeaders)
|
|
111
112
|
});
|
|
@@ -120,7 +121,7 @@ const standaloneRepository = (config, hooks) => {
|
|
|
120
121
|
}
|
|
121
122
|
} else if (op.operation === "insert" || op.operation === "update") {
|
|
122
123
|
const { path: path$1, headers: routeHeaders } = routes.upsert();
|
|
123
|
-
const response = await fetch(
|
|
124
|
+
const response = await fetch(buildUrl(path$1), {
|
|
124
125
|
method: "POST",
|
|
125
126
|
headers: getHeaders(routeHeaders),
|
|
126
127
|
body: JSON.stringify([op.data])
|
|
@@ -1442,8 +1443,9 @@ var require_mime = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/mime@2
|
|
|
1442
1443
|
//#region src/standaloneStorage.ts
|
|
1443
1444
|
var import_mime = /* @__PURE__ */ __toESM(require_mime(), 1);
|
|
1444
1445
|
const defaultRoutes = {
|
|
1445
|
-
|
|
1446
|
-
|
|
1446
|
+
upload: (_key, _filePath) => ({ path: "/upload" }),
|
|
1447
|
+
delete: (_storageUri) => ({ path: "/delete" }),
|
|
1448
|
+
getDownloadUrl: (_storageUri) => ({ path: "/getDownloadUrl" })
|
|
1447
1449
|
};
|
|
1448
1450
|
const createRoute = (defaultRoute, customRoute) => ({
|
|
1449
1451
|
path: customRoute?.path ?? defaultRoute.path,
|
|
@@ -1454,8 +1456,9 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
1454
1456
|
});
|
|
1455
1457
|
const standaloneStorage = (config, hooks) => (_) => {
|
|
1456
1458
|
const routes = {
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
+
upload: (key, filePath) => createRoute(defaultRoutes.upload(key, filePath), config.routes?.upload?.(key, filePath)),
|
|
1460
|
+
delete: (storageUri) => createRoute(defaultRoutes.delete(storageUri), config.routes?.delete?.(storageUri)),
|
|
1461
|
+
getDownloadUrl: (storageUri) => createRoute(defaultRoutes.getDownloadUrl(storageUri), config.routes?.getDownloadUrl?.(storageUri))
|
|
1459
1462
|
};
|
|
1460
1463
|
const getHeaders = (routeHeaders) => ({
|
|
1461
1464
|
...config.commonHeaders,
|
|
@@ -1463,28 +1466,28 @@ const standaloneStorage = (config, hooks) => (_) => {
|
|
|
1463
1466
|
});
|
|
1464
1467
|
return {
|
|
1465
1468
|
name: "standaloneStorage",
|
|
1466
|
-
|
|
1467
|
-
|
|
1469
|
+
supportedProtocol: "http",
|
|
1470
|
+
async delete(storageUri) {
|
|
1471
|
+
const { path: routePath, headers: routeHeaders } = routes.delete(storageUri);
|
|
1468
1472
|
const response = await fetch(`${config.baseUrl}${routePath}`, {
|
|
1469
1473
|
method: "DELETE",
|
|
1470
1474
|
headers: getHeaders(routeHeaders),
|
|
1471
|
-
body: JSON.stringify({
|
|
1475
|
+
body: JSON.stringify({ storageUri })
|
|
1472
1476
|
});
|
|
1473
1477
|
if (!response.ok) {
|
|
1474
1478
|
const error = /* @__PURE__ */ new Error(`Failed to delete bundle: ${response.statusText}`);
|
|
1475
1479
|
console.error(error);
|
|
1476
1480
|
throw error;
|
|
1477
1481
|
}
|
|
1478
|
-
return { storageUri: (await response.json()).storageUri };
|
|
1479
1482
|
},
|
|
1480
|
-
async
|
|
1481
|
-
const fileContent = await fs.readFile(
|
|
1482
|
-
const contentType = import_mime.default.getType(
|
|
1483
|
-
const filename = path.basename(
|
|
1484
|
-
const { path: routePath, headers: routeHeaders } = routes.
|
|
1483
|
+
async upload(key, filePath) {
|
|
1484
|
+
const fileContent = await fs.readFile(filePath);
|
|
1485
|
+
const contentType = import_mime.default.getType(filePath) ?? "application/octet-stream";
|
|
1486
|
+
const filename = path.basename(filePath);
|
|
1487
|
+
const { path: routePath, headers: routeHeaders } = routes.upload(key, filePath);
|
|
1485
1488
|
const formData = new FormData();
|
|
1486
1489
|
formData.append("file", new Blob([fileContent], { type: contentType }), filename);
|
|
1487
|
-
formData.append("
|
|
1490
|
+
formData.append("key", key);
|
|
1488
1491
|
const response = await fetch(`${config.baseUrl}${routePath}`, {
|
|
1489
1492
|
method: "POST",
|
|
1490
1493
|
headers: getHeaders(routeHeaders),
|
|
@@ -1492,17 +1495,31 @@ const standaloneStorage = (config, hooks) => (_) => {
|
|
|
1492
1495
|
});
|
|
1493
1496
|
if (!response.ok) {
|
|
1494
1497
|
const error = `Failed to upload bundle: ${response.statusText}`;
|
|
1495
|
-
console.error(`[
|
|
1498
|
+
console.error(`[upload] ${error}`);
|
|
1496
1499
|
throw new Error(error);
|
|
1497
1500
|
}
|
|
1498
1501
|
const result = await response.json();
|
|
1499
1502
|
if (!result.storageUri) {
|
|
1500
1503
|
const error = "Failed to upload bundle - no storageUri in response";
|
|
1501
|
-
console.error(`[
|
|
1504
|
+
console.error(`[upload] ${error}`);
|
|
1502
1505
|
throw new Error(error);
|
|
1503
1506
|
}
|
|
1504
1507
|
hooks?.onStorageUploaded?.();
|
|
1505
1508
|
return { storageUri: result.storageUri };
|
|
1509
|
+
},
|
|
1510
|
+
async getDownloadUrl(storageUri) {
|
|
1511
|
+
const { path: routePath, headers: routeHeaders } = routes.getDownloadUrl(storageUri);
|
|
1512
|
+
const response = await fetch(`${config.baseUrl}${routePath}`, {
|
|
1513
|
+
method: "POST",
|
|
1514
|
+
headers: getHeaders(routeHeaders),
|
|
1515
|
+
body: JSON.stringify({ storageUri })
|
|
1516
|
+
});
|
|
1517
|
+
if (!response.ok) {
|
|
1518
|
+
const error = /* @__PURE__ */ new Error(`Failed to get download URL: ${response.statusText}`);
|
|
1519
|
+
console.error(error);
|
|
1520
|
+
throw error;
|
|
1521
|
+
}
|
|
1522
|
+
return { fileUrl: (await response.json()).fileUrl };
|
|
1506
1523
|
}
|
|
1507
1524
|
};
|
|
1508
1525
|
};
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/standalone",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
7
|
-
"main": "dist/index.cjs",
|
|
8
|
-
"module": "dist/index.js",
|
|
9
|
-
"types": "dist/index.d.
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.cts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
12
|
"import": "./dist/index.js",
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
|
-
}
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
15
16
|
},
|
|
16
17
|
"files": [
|
|
17
18
|
"dist",
|
|
@@ -38,8 +39,8 @@
|
|
|
38
39
|
"access": "public"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"@hot-updater/core": "0.
|
|
42
|
-
"@hot-updater/plugin-core": "0.
|
|
42
|
+
"@hot-updater/core": "0.21.0",
|
|
43
|
+
"@hot-updater/plugin-core": "0.21.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"mime": "2.6.0",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"@types/semver": "^7.5.8",
|
|
49
50
|
"msw": "^2.7.0",
|
|
50
51
|
"semver": "^7.6.3",
|
|
51
|
-
"vitest": "^3.
|
|
52
|
+
"vitest": "^3.2.4"
|
|
52
53
|
},
|
|
53
54
|
"scripts": {
|
|
54
55
|
"build": "tsdown",
|