@hot-updater/standalone 0.21.10 → 0.21.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.
- package/dist/index.cjs +81 -79
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +81 -79
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -51,91 +51,93 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
|
|
|
51
51
|
...customRoute?.headers
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
-
const standaloneRepository = (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
54
|
+
const standaloneRepository = (0, __hot_updater_plugin_core.createDatabasePlugin)({
|
|
55
|
+
name: "standalone-repository",
|
|
56
|
+
factory: (config) => {
|
|
57
|
+
const routes = {
|
|
58
|
+
upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
|
|
59
|
+
list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
|
|
60
|
+
retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
|
|
61
|
+
delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
|
|
62
|
+
};
|
|
63
|
+
const buildUrl = (path$2) => `${config.baseUrl}${path$2}`;
|
|
64
|
+
const getHeaders = (routeHeaders) => ({
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
...config.commonHeaders,
|
|
67
|
+
...routeHeaders
|
|
68
|
+
});
|
|
69
|
+
return {
|
|
70
|
+
async getBundleById(bundleId) {
|
|
71
|
+
try {
|
|
72
|
+
const { path: path$2, headers: routeHeaders } = routes.retrieve(bundleId);
|
|
73
|
+
const response = await fetch(buildUrl(path$2), {
|
|
74
|
+
method: "GET",
|
|
75
|
+
headers: getHeaders(routeHeaders)
|
|
76
|
+
});
|
|
77
|
+
if (!response.ok) return null;
|
|
78
|
+
return await response.json();
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
async getBundles(options) {
|
|
84
|
+
const { where, limit, offset = 0 } = options ?? {};
|
|
85
|
+
const { path: path$2, headers: routeHeaders } = routes.list();
|
|
71
86
|
const response = await fetch(buildUrl(path$2), {
|
|
72
87
|
method: "GET",
|
|
73
88
|
headers: getHeaders(routeHeaders)
|
|
74
89
|
});
|
|
75
|
-
if (!response.ok)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const total = filteredBundles.length;
|
|
93
|
-
return {
|
|
94
|
-
data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
|
|
95
|
-
pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
|
|
96
|
-
limit,
|
|
97
|
-
offset
|
|
98
|
-
})
|
|
99
|
-
};
|
|
100
|
-
},
|
|
101
|
-
async getChannels(_) {
|
|
102
|
-
const result = await this.getBundles(_, {
|
|
103
|
-
limit: 50,
|
|
104
|
-
offset: 0
|
|
105
|
-
});
|
|
106
|
-
return [...new Set(result.data.map((b) => b.channel))];
|
|
107
|
-
},
|
|
108
|
-
async commitBundle(_, { changedSets }) {
|
|
109
|
-
if (changedSets.length === 0) return;
|
|
110
|
-
for (const op of changedSets) if (op.operation === "delete") {
|
|
111
|
-
const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
|
|
112
|
-
const response = await fetch(buildUrl(path$2), {
|
|
113
|
-
method: "DELETE",
|
|
114
|
-
headers: getHeaders(routeHeaders)
|
|
90
|
+
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
91
|
+
let filteredBundles = await response.json();
|
|
92
|
+
if (where?.channel) filteredBundles = filteredBundles.filter((b) => b.channel === where.channel);
|
|
93
|
+
if (where?.platform) filteredBundles = filteredBundles.filter((b) => b.platform === where.platform);
|
|
94
|
+
const total = filteredBundles.length;
|
|
95
|
+
return {
|
|
96
|
+
data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
|
|
97
|
+
pagination: (0, __hot_updater_plugin_core.calculatePagination)(total, {
|
|
98
|
+
limit,
|
|
99
|
+
offset
|
|
100
|
+
})
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
async getChannels() {
|
|
104
|
+
const result = await this.getBundles({
|
|
105
|
+
limit: 50,
|
|
106
|
+
offset: 0
|
|
115
107
|
});
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
return [...new Set(result.data.map((b) => b.channel))];
|
|
109
|
+
},
|
|
110
|
+
async commitBundle({ changedSets }) {
|
|
111
|
+
if (changedSets.length === 0) return;
|
|
112
|
+
for (const op of changedSets) if (op.operation === "delete") {
|
|
113
|
+
const { path: path$2, headers: routeHeaders } = routes.delete(op.data.id);
|
|
114
|
+
const response = await fetch(buildUrl(path$2), {
|
|
115
|
+
method: "DELETE",
|
|
116
|
+
headers: getHeaders(routeHeaders)
|
|
117
|
+
});
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
if (response.status === 404) throw new Error(`Bundle with id ${op.data.id} not found`);
|
|
120
|
+
throw new Error(`API Error: ${response.status} ${response.statusText}`);
|
|
121
|
+
}
|
|
122
|
+
if (response.headers.get("content-type")?.includes("application/json")) try {
|
|
123
|
+
await response.json();
|
|
124
|
+
} catch (_jsonError) {
|
|
125
|
+
if (!response.ok) throw new Error("Failed to parse response");
|
|
126
|
+
}
|
|
127
|
+
} else if (op.operation === "insert" || op.operation === "update") {
|
|
128
|
+
const { path: path$2, headers: routeHeaders } = routes.upsert();
|
|
129
|
+
const response = await fetch(buildUrl(path$2), {
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers: getHeaders(routeHeaders),
|
|
132
|
+
body: JSON.stringify([op.data])
|
|
133
|
+
});
|
|
134
|
+
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
135
|
+
if (!(await response.json()).success) throw new Error("Failed to commit bundle");
|
|
124
136
|
}
|
|
125
|
-
} else if (op.operation === "insert" || op.operation === "update") {
|
|
126
|
-
const { path: path$2, headers: routeHeaders } = routes.upsert();
|
|
127
|
-
const response = await fetch(buildUrl(path$2), {
|
|
128
|
-
method: "POST",
|
|
129
|
-
headers: getHeaders(routeHeaders),
|
|
130
|
-
body: JSON.stringify([op.data])
|
|
131
|
-
});
|
|
132
|
-
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
133
|
-
if (!(await response.json()).success) throw new Error("Failed to commit bundle");
|
|
134
137
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
};
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
});
|
|
139
141
|
|
|
140
142
|
//#endregion
|
|
141
143
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
|
|
@@ -1457,7 +1459,7 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
1457
1459
|
...customRoute?.headers
|
|
1458
1460
|
}
|
|
1459
1461
|
});
|
|
1460
|
-
const standaloneStorage = (config, hooks) => (
|
|
1462
|
+
const standaloneStorage = (config, hooks) => () => {
|
|
1461
1463
|
const routes = {
|
|
1462
1464
|
upload: (key, filePath) => createRoute(defaultRoutes.upload(key, filePath), config.routes?.upload?.(key, filePath)),
|
|
1463
1465
|
delete: (storageUri) => createRoute(defaultRoutes.delete(storageUri), config.routes?.delete?.(storageUri)),
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
|
-
import {
|
|
2
|
+
import { StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
|
|
3
3
|
|
|
4
4
|
//#region src/standaloneRepository.d.ts
|
|
5
5
|
interface RouteConfig {
|
|
@@ -17,7 +17,7 @@ interface StandaloneRepositoryConfig {
|
|
|
17
17
|
commonHeaders?: Record<string, string>;
|
|
18
18
|
routes?: Routes;
|
|
19
19
|
}
|
|
20
|
-
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: DatabasePluginHooks) => (
|
|
20
|
+
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (() => _hot_updater_plugin_core0.DatabasePlugin);
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/standaloneStorage.d.ts
|
|
23
23
|
interface StorageRoutes {
|
|
@@ -30,6 +30,6 @@ interface StandaloneStorageConfig {
|
|
|
30
30
|
commonHeaders?: Record<string, string>;
|
|
31
31
|
routes?: StorageRoutes;
|
|
32
32
|
}
|
|
33
|
-
declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => (
|
|
33
|
+
declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
|
|
34
34
|
//#endregion
|
|
35
35
|
export { RouteConfig, Routes, StandaloneRepositoryConfig, StandaloneStorageConfig, StorageRoutes, standaloneRepository, standaloneStorage };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
|
-
import {
|
|
2
|
+
import { StoragePlugin, StoragePluginHooks } from "@hot-updater/plugin-core";
|
|
3
3
|
|
|
4
4
|
//#region src/standaloneRepository.d.ts
|
|
5
5
|
interface RouteConfig {
|
|
@@ -17,7 +17,7 @@ interface StandaloneRepositoryConfig {
|
|
|
17
17
|
commonHeaders?: Record<string, string>;
|
|
18
18
|
routes?: Routes;
|
|
19
19
|
}
|
|
20
|
-
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: DatabasePluginHooks) => (
|
|
20
|
+
declare const standaloneRepository: (config: StandaloneRepositoryConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (() => _hot_updater_plugin_core0.DatabasePlugin);
|
|
21
21
|
//#endregion
|
|
22
22
|
//#region src/standaloneStorage.d.ts
|
|
23
23
|
interface StorageRoutes {
|
|
@@ -30,6 +30,6 @@ interface StandaloneStorageConfig {
|
|
|
30
30
|
commonHeaders?: Record<string, string>;
|
|
31
31
|
routes?: StorageRoutes;
|
|
32
32
|
}
|
|
33
|
-
declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => (
|
|
33
|
+
declare const standaloneStorage: (config: StandaloneStorageConfig, hooks?: StoragePluginHooks) => () => StoragePlugin;
|
|
34
34
|
//#endregion
|
|
35
35
|
export { RouteConfig, Routes, StandaloneRepositoryConfig, StandaloneStorageConfig, StorageRoutes, standaloneRepository, standaloneStorage };
|
package/dist/index.js
CHANGED
|
@@ -48,91 +48,93 @@ const createRoute$1 = (defaultRoute, customRoute) => ({
|
|
|
48
48
|
...customRoute?.headers
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
|
-
const standaloneRepository = (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
51
|
+
const standaloneRepository = createDatabasePlugin({
|
|
52
|
+
name: "standalone-repository",
|
|
53
|
+
factory: (config) => {
|
|
54
|
+
const routes = {
|
|
55
|
+
upsert: () => createRoute$1(defaultRoutes$1.upsert(), config.routes?.upsert?.()),
|
|
56
|
+
list: () => createRoute$1(defaultRoutes$1.list(), config.routes?.list?.()),
|
|
57
|
+
retrieve: (bundleId) => createRoute$1(defaultRoutes$1.retrieve(bundleId), config.routes?.retrieve?.(bundleId)),
|
|
58
|
+
delete: (bundleId) => createRoute$1(defaultRoutes$1.delete(bundleId), config.routes?.delete?.(bundleId))
|
|
59
|
+
};
|
|
60
|
+
const buildUrl = (path$1) => `${config.baseUrl}${path$1}`;
|
|
61
|
+
const getHeaders = (routeHeaders) => ({
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
...config.commonHeaders,
|
|
64
|
+
...routeHeaders
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
async getBundleById(bundleId) {
|
|
68
|
+
try {
|
|
69
|
+
const { path: path$1, headers: routeHeaders } = routes.retrieve(bundleId);
|
|
70
|
+
const response = await fetch(buildUrl(path$1), {
|
|
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$1, headers: routeHeaders } = routes.list();
|
|
68
83
|
const response = await fetch(buildUrl(path$1), {
|
|
69
84
|
method: "GET",
|
|
70
85
|
headers: getHeaders(routeHeaders)
|
|
71
86
|
});
|
|
72
|
-
if (!response.ok)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const total = filteredBundles.length;
|
|
90
|
-
return {
|
|
91
|
-
data: limit ? filteredBundles.slice(offset, offset + limit) : filteredBundles,
|
|
92
|
-
pagination: calculatePagination(total, {
|
|
93
|
-
limit,
|
|
94
|
-
offset
|
|
95
|
-
})
|
|
96
|
-
};
|
|
97
|
-
},
|
|
98
|
-
async getChannels(_) {
|
|
99
|
-
const result = await this.getBundles(_, {
|
|
100
|
-
limit: 50,
|
|
101
|
-
offset: 0
|
|
102
|
-
});
|
|
103
|
-
return [...new Set(result.data.map((b) => b.channel))];
|
|
104
|
-
},
|
|
105
|
-
async commitBundle(_, { changedSets }) {
|
|
106
|
-
if (changedSets.length === 0) return;
|
|
107
|
-
for (const op of changedSets) if (op.operation === "delete") {
|
|
108
|
-
const { path: path$1, headers: routeHeaders } = routes.delete(op.data.id);
|
|
109
|
-
const response = await fetch(buildUrl(path$1), {
|
|
110
|
-
method: "DELETE",
|
|
111
|
-
headers: getHeaders(routeHeaders)
|
|
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: calculatePagination(total, {
|
|
95
|
+
limit,
|
|
96
|
+
offset
|
|
97
|
+
})
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
async getChannels() {
|
|
101
|
+
const result = await this.getBundles({
|
|
102
|
+
limit: 50,
|
|
103
|
+
offset: 0
|
|
112
104
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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$1, headers: routeHeaders } = routes.delete(op.data.id);
|
|
111
|
+
const response = await fetch(buildUrl(path$1), {
|
|
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$1, headers: routeHeaders } = routes.upsert();
|
|
126
|
+
const response = await fetch(buildUrl(path$1), {
|
|
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");
|
|
121
133
|
}
|
|
122
|
-
} else if (op.operation === "insert" || op.operation === "update") {
|
|
123
|
-
const { path: path$1, headers: routeHeaders } = routes.upsert();
|
|
124
|
-
const response = await fetch(buildUrl(path$1), {
|
|
125
|
-
method: "POST",
|
|
126
|
-
headers: getHeaders(routeHeaders),
|
|
127
|
-
body: JSON.stringify([op.data])
|
|
128
|
-
});
|
|
129
|
-
if (!response.ok) throw new Error(`API Error: ${response.statusText}`);
|
|
130
|
-
if (!(await response.json()).success) throw new Error("Failed to commit bundle");
|
|
131
134
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
};
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
});
|
|
136
138
|
|
|
137
139
|
//#endregion
|
|
138
140
|
//#region ../../node_modules/.pnpm/mime@2.6.0/node_modules/mime/Mime.js
|
|
@@ -1454,7 +1456,7 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
1454
1456
|
...customRoute?.headers
|
|
1455
1457
|
}
|
|
1456
1458
|
});
|
|
1457
|
-
const standaloneStorage = (config, hooks) => (
|
|
1459
|
+
const standaloneStorage = (config, hooks) => () => {
|
|
1458
1460
|
const routes = {
|
|
1459
1461
|
upload: (key, filePath) => createRoute(defaultRoutes.upload(key, filePath), config.routes?.upload?.(key, filePath)),
|
|
1460
1462
|
delete: (storageUri) => createRoute(defaultRoutes.delete(storageUri), config.routes?.delete?.(storageUri)),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/standalone",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@hot-updater/core": "0.21.
|
|
43
|
-
"@hot-updater/plugin-core": "0.21.
|
|
42
|
+
"@hot-updater/core": "0.21.12",
|
|
43
|
+
"@hot-updater/plugin-core": "0.21.12"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"mime": "2.6.0",
|