@hot-updater/server 0.29.8 → 0.30.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/db/index.cjs +1 -0
- package/dist/db/index.d.cts +1 -0
- package/dist/db/index.d.mts +1 -0
- package/dist/db/index.mjs +1 -0
- package/dist/handler.cjs +4 -2
- package/dist/handler.d.cts +7 -1
- package/dist/handler.d.mts +7 -1
- package/dist/handler.mjs +4 -2
- package/dist/index.cjs +2 -0
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/package.cjs +9 -0
- package/dist/package.mjs +4 -0
- package/dist/runtime.cjs +2 -0
- package/dist/runtime.d.cts +2 -1
- package/dist/runtime.d.mts +2 -1
- package/dist/runtime.mjs +2 -1
- package/dist/version.cjs +4 -0
- package/dist/version.d.cts +4 -0
- package/dist/version.d.mts +4 -0
- package/dist/version.mjs +5 -0
- package/package.json +6 -6
- package/src/db/index.ts +1 -0
- package/src/handler.spec.ts +41 -2
- package/src/handler.ts +14 -5
- package/src/index.ts +1 -0
- package/src/runtime.spec.ts +89 -0
- package/src/runtime.ts +1 -0
- package/src/version.ts +3 -0
package/dist/db/index.cjs
CHANGED
package/dist/db/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HandlerRoutes } from "../handler.cjs";
|
|
2
2
|
import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./types.cjs";
|
|
3
3
|
import { HotUpdaterClient, HotUpdaterDB, Migrator } from "./ormCore.cjs";
|
|
4
|
+
import { HOT_UPDATER_SERVER_VERSION } from "../version.cjs";
|
|
4
5
|
import { HotUpdaterContext, StoragePlugin } from "@hot-updater/plugin-core";
|
|
5
6
|
|
|
6
7
|
//#region src/db/index.d.ts
|
package/dist/db/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HandlerRoutes } from "../handler.mjs";
|
|
2
2
|
import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./types.mjs";
|
|
3
3
|
import { HotUpdaterClient, HotUpdaterDB, Migrator } from "./ormCore.mjs";
|
|
4
|
+
import { HOT_UPDATER_SERVER_VERSION } from "../version.mjs";
|
|
4
5
|
import { HotUpdaterContext, StoragePlugin } from "@hot-updater/plugin-core";
|
|
5
6
|
|
|
6
7
|
//#region src/db/index.d.ts
|
package/dist/db/index.mjs
CHANGED
package/dist/handler.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const require_internalRouter = require("./internalRouter.cjs");
|
|
2
|
+
const require_version = require("./version.cjs");
|
|
2
3
|
//#region src/handler.ts
|
|
3
4
|
var HandlerBadRequestError = class extends Error {
|
|
4
5
|
constructor(message) {
|
|
@@ -7,7 +8,7 @@ var HandlerBadRequestError = class extends Error {
|
|
|
7
8
|
}
|
|
8
9
|
};
|
|
9
10
|
const handleVersion = async () => {
|
|
10
|
-
return new Response(JSON.stringify({ version:
|
|
11
|
+
return new Response(JSON.stringify({ version: require_version.HOT_UPDATER_SERVER_VERSION }), {
|
|
11
12
|
status: 200,
|
|
12
13
|
headers: { "Content-Type": "application/json" }
|
|
13
14
|
});
|
|
@@ -175,8 +176,10 @@ const routes = {
|
|
|
175
176
|
function createHandler(api, options = {}) {
|
|
176
177
|
const basePath = options.basePath ?? "/api";
|
|
177
178
|
const updateCheckEnabled = options.routes?.updateCheck ?? true;
|
|
179
|
+
const versionEnabled = options.routes?.version ?? true;
|
|
178
180
|
const bundlesEnabled = options.routes?.bundles ?? true;
|
|
179
181
|
const router = require_internalRouter.createRouter();
|
|
182
|
+
if (versionEnabled) require_internalRouter.addRoute(router, "GET", "/version", "version");
|
|
180
183
|
if (updateCheckEnabled) {
|
|
181
184
|
require_internalRouter.addRoute(router, "GET", "/fingerprint/:platform/:fingerprintHash/:channel/:minBundleId/:bundleId", "fingerprintUpdateWithCohort");
|
|
182
185
|
require_internalRouter.addRoute(router, "GET", "/fingerprint/:platform/:fingerprintHash/:channel/:minBundleId/:bundleId/:cohort", "fingerprintUpdateWithCohort");
|
|
@@ -184,7 +187,6 @@ function createHandler(api, options = {}) {
|
|
|
184
187
|
require_internalRouter.addRoute(router, "GET", "/app-version/:platform/:appVersion/:channel/:minBundleId/:bundleId/:cohort", "appVersionUpdateWithCohort");
|
|
185
188
|
}
|
|
186
189
|
if (bundlesEnabled) {
|
|
187
|
-
require_internalRouter.addRoute(router, "GET", "/version", "version");
|
|
188
190
|
require_internalRouter.addRoute(router, "GET", "/api/bundles/channels", "getChannels");
|
|
189
191
|
require_internalRouter.addRoute(router, "GET", "/api/bundles/:id", "getBundle");
|
|
190
192
|
require_internalRouter.addRoute(router, "GET", "/api/bundles", "getBundles");
|
package/dist/handler.d.cts
CHANGED
|
@@ -26,9 +26,15 @@ interface HandlerRoutes {
|
|
|
26
26
|
* @default true
|
|
27
27
|
*/
|
|
28
28
|
updateCheck?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Controls whether the `/version` endpoint is mounted.
|
|
31
|
+
* Useful for diagnostics and lightweight health/version checks.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
version?: boolean;
|
|
29
35
|
/**
|
|
30
36
|
* Controls whether bundle management routes are mounted.
|
|
31
|
-
* This includes `/
|
|
37
|
+
* This includes `/api/bundles*`, which are used by the
|
|
32
38
|
* CLI `standaloneRepository` plugin.
|
|
33
39
|
* @default true
|
|
34
40
|
*/
|
package/dist/handler.d.mts
CHANGED
|
@@ -26,9 +26,15 @@ interface HandlerRoutes {
|
|
|
26
26
|
* @default true
|
|
27
27
|
*/
|
|
28
28
|
updateCheck?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Controls whether the `/version` endpoint is mounted.
|
|
31
|
+
* Useful for diagnostics and lightweight health/version checks.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
version?: boolean;
|
|
29
35
|
/**
|
|
30
36
|
* Controls whether bundle management routes are mounted.
|
|
31
|
-
* This includes `/
|
|
37
|
+
* This includes `/api/bundles*`, which are used by the
|
|
32
38
|
* CLI `standaloneRepository` plugin.
|
|
33
39
|
* @default true
|
|
34
40
|
*/
|
package/dist/handler.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { addRoute, createRouter, findRoute } from "./internalRouter.mjs";
|
|
2
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version.mjs";
|
|
2
3
|
//#region src/handler.ts
|
|
3
4
|
var HandlerBadRequestError = class extends Error {
|
|
4
5
|
constructor(message) {
|
|
@@ -7,7 +8,7 @@ var HandlerBadRequestError = class extends Error {
|
|
|
7
8
|
}
|
|
8
9
|
};
|
|
9
10
|
const handleVersion = async () => {
|
|
10
|
-
return new Response(JSON.stringify({ version:
|
|
11
|
+
return new Response(JSON.stringify({ version: HOT_UPDATER_SERVER_VERSION }), {
|
|
11
12
|
status: 200,
|
|
12
13
|
headers: { "Content-Type": "application/json" }
|
|
13
14
|
});
|
|
@@ -175,8 +176,10 @@ const routes = {
|
|
|
175
176
|
function createHandler(api, options = {}) {
|
|
176
177
|
const basePath = options.basePath ?? "/api";
|
|
177
178
|
const updateCheckEnabled = options.routes?.updateCheck ?? true;
|
|
179
|
+
const versionEnabled = options.routes?.version ?? true;
|
|
178
180
|
const bundlesEnabled = options.routes?.bundles ?? true;
|
|
179
181
|
const router = createRouter();
|
|
182
|
+
if (versionEnabled) addRoute(router, "GET", "/version", "version");
|
|
180
183
|
if (updateCheckEnabled) {
|
|
181
184
|
addRoute(router, "GET", "/fingerprint/:platform/:fingerprintHash/:channel/:minBundleId/:bundleId", "fingerprintUpdateWithCohort");
|
|
182
185
|
addRoute(router, "GET", "/fingerprint/:platform/:fingerprintHash/:channel/:minBundleId/:bundleId/:cohort", "fingerprintUpdateWithCohort");
|
|
@@ -184,7 +187,6 @@ function createHandler(api, options = {}) {
|
|
|
184
187
|
addRoute(router, "GET", "/app-version/:platform/:appVersion/:channel/:minBundleId/:bundleId/:cohort", "appVersionUpdateWithCohort");
|
|
185
188
|
}
|
|
186
189
|
if (bundlesEnabled) {
|
|
187
|
-
addRoute(router, "GET", "/version", "version");
|
|
188
190
|
addRoute(router, "GET", "/api/bundles/channels", "getChannels");
|
|
189
191
|
addRoute(router, "GET", "/api/bundles/:id", "getBundle");
|
|
190
192
|
addRoute(router, "GET", "/api/bundles", "getBundles");
|
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_version = require("./version.cjs");
|
|
2
3
|
const require_handler = require("./handler.cjs");
|
|
3
4
|
const require_ormCore = require("./db/ormCore.cjs");
|
|
4
5
|
const require_index = require("./db/index.cjs");
|
|
6
|
+
exports.HOT_UPDATER_SERVER_VERSION = require_version.HOT_UPDATER_SERVER_VERSION;
|
|
5
7
|
exports.HotUpdaterDB = require_ormCore.HotUpdaterDB;
|
|
6
8
|
exports.createHandler = require_handler.createHandler;
|
|
7
9
|
exports.createHotUpdater = require_index.createHotUpdater;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bundle, ChannelsResponse, DataResponse, Paginated, PaginatedResult, PaginationInfo, PaginationOptions } from "./types/index.cjs";
|
|
2
2
|
import { HandlerAPI, HandlerOptions, HandlerRoutes, createHandler } from "./handler.cjs";
|
|
3
3
|
import { HotUpdaterClient, HotUpdaterDB, Migrator } from "./db/ormCore.cjs";
|
|
4
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version.cjs";
|
|
4
5
|
import { CreateHotUpdaterOptions, HotUpdaterAPI, createHotUpdater } from "./db/index.cjs";
|
|
5
|
-
export { Bundle, ChannelsResponse, CreateHotUpdaterOptions, DataResponse, HandlerAPI, HandlerOptions, HandlerRoutes, HotUpdaterAPI, HotUpdaterClient, HotUpdaterDB, Migrator, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, createHandler, createHotUpdater };
|
|
6
|
+
export { Bundle, ChannelsResponse, CreateHotUpdaterOptions, DataResponse, HOT_UPDATER_SERVER_VERSION, HandlerAPI, HandlerOptions, HandlerRoutes, HotUpdaterAPI, HotUpdaterClient, HotUpdaterDB, Migrator, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, createHandler, createHotUpdater };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bundle, ChannelsResponse, DataResponse, Paginated, PaginatedResult, PaginationInfo, PaginationOptions } from "./types/index.mjs";
|
|
2
2
|
import { HandlerAPI, HandlerOptions, HandlerRoutes, createHandler } from "./handler.mjs";
|
|
3
3
|
import { HotUpdaterClient, HotUpdaterDB, Migrator } from "./db/ormCore.mjs";
|
|
4
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version.mjs";
|
|
4
5
|
import { CreateHotUpdaterOptions, HotUpdaterAPI, createHotUpdater } from "./db/index.mjs";
|
|
5
|
-
export { Bundle, ChannelsResponse, CreateHotUpdaterOptions, DataResponse, HandlerAPI, HandlerOptions, HandlerRoutes, HotUpdaterAPI, HotUpdaterClient, HotUpdaterDB, Migrator, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, createHandler, createHotUpdater };
|
|
6
|
+
export { Bundle, ChannelsResponse, CreateHotUpdaterOptions, DataResponse, HOT_UPDATER_SERVER_VERSION, HandlerAPI, HandlerOptions, HandlerRoutes, HotUpdaterAPI, HotUpdaterClient, HotUpdaterDB, Migrator, Paginated, PaginatedResult, PaginationInfo, PaginationOptions, createHandler, createHotUpdater };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version.mjs";
|
|
1
2
|
import { createHandler } from "./handler.mjs";
|
|
2
3
|
import { HotUpdaterDB } from "./db/ormCore.mjs";
|
|
3
4
|
import { createHotUpdater } from "./db/index.mjs";
|
|
4
|
-
export { HotUpdaterDB, createHandler, createHotUpdater };
|
|
5
|
+
export { HOT_UPDATER_SERVER_VERSION, HotUpdaterDB, createHandler, createHotUpdater };
|
package/dist/package.cjs
ADDED
package/dist/package.mjs
ADDED
package/dist/runtime.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_version = require("./version.cjs");
|
|
2
3
|
const require_handler = require("./handler.cjs");
|
|
3
4
|
const require_route = require("./route.cjs");
|
|
4
5
|
const require_pluginCore = require("./db/pluginCore.cjs");
|
|
@@ -40,5 +41,6 @@ function createHotUpdater(options) {
|
|
|
40
41
|
};
|
|
41
42
|
}
|
|
42
43
|
//#endregion
|
|
44
|
+
exports.HOT_UPDATER_SERVER_VERSION = require_version.HOT_UPDATER_SERVER_VERSION;
|
|
43
45
|
exports.createHandler = require_handler.createHandler;
|
|
44
46
|
exports.createHotUpdater = createHotUpdater;
|
package/dist/runtime.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HandlerRoutes, createHandler } from "./handler.cjs";
|
|
2
2
|
import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./db/types.cjs";
|
|
3
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version.cjs";
|
|
3
4
|
import { HotUpdaterContext, StoragePlugin } from "@hot-updater/plugin-core";
|
|
4
5
|
|
|
5
6
|
//#region src/runtime.d.ts
|
|
@@ -18,4 +19,4 @@ interface CreateHotUpdaterOptions<TContext = unknown> {
|
|
|
18
19
|
}
|
|
19
20
|
declare function createHotUpdater<TContext = unknown>(options: CreateHotUpdaterOptions<TContext>): HotUpdaterAPI<TContext>;
|
|
20
21
|
//#endregion
|
|
21
|
-
export { CreateHotUpdaterOptions, HotUpdaterAPI, createHandler, createHotUpdater };
|
|
22
|
+
export { CreateHotUpdaterOptions, HOT_UPDATER_SERVER_VERSION, HotUpdaterAPI, createHandler, createHotUpdater };
|
package/dist/runtime.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HandlerRoutes, createHandler } from "./handler.mjs";
|
|
2
2
|
import { DatabaseAPI, DatabaseAdapter, StoragePluginFactory } from "./db/types.mjs";
|
|
3
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version.mjs";
|
|
3
4
|
import { HotUpdaterContext, StoragePlugin } from "@hot-updater/plugin-core";
|
|
4
5
|
|
|
5
6
|
//#region src/runtime.d.ts
|
|
@@ -18,4 +19,4 @@ interface CreateHotUpdaterOptions<TContext = unknown> {
|
|
|
18
19
|
}
|
|
19
20
|
declare function createHotUpdater<TContext = unknown>(options: CreateHotUpdaterOptions<TContext>): HotUpdaterAPI<TContext>;
|
|
20
21
|
//#endregion
|
|
21
|
-
export { CreateHotUpdaterOptions, HotUpdaterAPI, createHandler, createHotUpdater };
|
|
22
|
+
export { CreateHotUpdaterOptions, HOT_UPDATER_SERVER_VERSION, HotUpdaterAPI, createHandler, createHotUpdater };
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version.mjs";
|
|
1
2
|
import { createHandler } from "./handler.mjs";
|
|
2
3
|
import { normalizeBasePath } from "./route.mjs";
|
|
3
4
|
import { createPluginDatabaseCore } from "./db/pluginCore.mjs";
|
|
@@ -39,4 +40,4 @@ function createHotUpdater(options) {
|
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
42
|
//#endregion
|
|
42
|
-
export { createHandler, createHotUpdater };
|
|
43
|
+
export { HOT_UPDATER_SERVER_VERSION, createHandler, createHotUpdater };
|
package/dist/version.cjs
ADDED
package/dist/version.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"fumadb": "0.2.2",
|
|
54
54
|
"rou3": "0.7.9",
|
|
55
55
|
"semver": "^7.7.2",
|
|
56
|
-
"@hot-updater/core": "0.
|
|
57
|
-
"@hot-updater/plugin-core": "0.
|
|
58
|
-
"@hot-updater/js": "0.
|
|
56
|
+
"@hot-updater/core": "0.30.0",
|
|
57
|
+
"@hot-updater/plugin-core": "0.30.0",
|
|
58
|
+
"@hot-updater/js": "0.30.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@electric-sql/pglite": "^0.2.17",
|
|
@@ -66,8 +66,8 @@
|
|
|
66
66
|
"kysely-pglite-dialect": "^1.2.0",
|
|
67
67
|
"msw": "^2.7.0",
|
|
68
68
|
"uuidv7": "^1.0.2",
|
|
69
|
-
"@hot-updater/standalone": "0.
|
|
70
|
-
"@hot-updater/test-utils": "0.
|
|
69
|
+
"@hot-updater/standalone": "0.30.0",
|
|
70
|
+
"@hot-updater/test-utils": "0.30.0"
|
|
71
71
|
},
|
|
72
72
|
"scripts": {
|
|
73
73
|
"build": "tsdown",
|
package/src/db/index.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
|
|
23
23
|
export type { HotUpdaterClient, Migrator } from "./ormCore";
|
|
24
24
|
export { HotUpdaterDB } from "./ormCore";
|
|
25
|
+
export { HOT_UPDATER_SERVER_VERSION } from "../version";
|
|
25
26
|
|
|
26
27
|
export type HotUpdaterAPI<TContext = unknown> = DatabaseAPI<TContext> & {
|
|
27
28
|
basePath: string;
|
package/src/handler.spec.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { type Bundle, NIL_UUID } from "@hot-updater/core";
|
|
|
2
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
3
|
|
|
4
4
|
import { createHandler, type HandlerAPI } from "./handler";
|
|
5
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version";
|
|
5
6
|
|
|
6
7
|
type TestEnv = {
|
|
7
8
|
tenantId: string;
|
|
@@ -107,7 +108,7 @@ describe("createHandler", () => {
|
|
|
107
108
|
);
|
|
108
109
|
});
|
|
109
110
|
|
|
110
|
-
it("
|
|
111
|
+
it("keeps version mounted when bundle routes are disabled", async () => {
|
|
111
112
|
const api = createApi();
|
|
112
113
|
const handler = createHandler(api, {
|
|
113
114
|
basePath: "/hot-updater",
|
|
@@ -129,12 +130,43 @@ describe("createHandler", () => {
|
|
|
129
130
|
),
|
|
130
131
|
);
|
|
131
132
|
|
|
133
|
+
expect(versionResponse.status).toBe(200);
|
|
134
|
+
await expect(versionResponse.json()).resolves.toEqual({
|
|
135
|
+
version: HOT_UPDATER_SERVER_VERSION,
|
|
136
|
+
});
|
|
137
|
+
expect(bundlesResponse.status).toBe(404);
|
|
138
|
+
expect(updateResponse.status).toBe(200);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("can disable the version route independently", async () => {
|
|
142
|
+
const api = createApi();
|
|
143
|
+
const handler = createHandler(api, {
|
|
144
|
+
basePath: "/hot-updater",
|
|
145
|
+
routes: {
|
|
146
|
+
updateCheck: true,
|
|
147
|
+
version: false,
|
|
148
|
+
bundles: false,
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const versionResponse = await handler(
|
|
153
|
+
new Request("http://localhost/hot-updater/version"),
|
|
154
|
+
);
|
|
155
|
+
const bundlesResponse = await handler(
|
|
156
|
+
new Request("http://localhost/hot-updater/api/bundles"),
|
|
157
|
+
);
|
|
158
|
+
const updateResponse = await handler(
|
|
159
|
+
new Request(
|
|
160
|
+
"http://localhost/hot-updater/app-version/ios/1.0.0/production/default/default",
|
|
161
|
+
),
|
|
162
|
+
);
|
|
163
|
+
|
|
132
164
|
expect(versionResponse.status).toBe(404);
|
|
133
165
|
expect(bundlesResponse.status).toBe(404);
|
|
134
166
|
expect(updateResponse.status).toBe(200);
|
|
135
167
|
});
|
|
136
168
|
|
|
137
|
-
it("can mount
|
|
169
|
+
it("can mount bundle routes without update-check routes", async () => {
|
|
138
170
|
const api = createApi();
|
|
139
171
|
const handler = createHandler(api, {
|
|
140
172
|
basePath: "/hot-updater",
|
|
@@ -144,6 +176,9 @@ describe("createHandler", () => {
|
|
|
144
176
|
},
|
|
145
177
|
});
|
|
146
178
|
|
|
179
|
+
const versionResponse = await handler(
|
|
180
|
+
new Request("http://localhost/hot-updater/version"),
|
|
181
|
+
);
|
|
147
182
|
const channelsResponse = await handler(
|
|
148
183
|
new Request("http://localhost/hot-updater/api/bundles/channels"),
|
|
149
184
|
);
|
|
@@ -153,6 +188,10 @@ describe("createHandler", () => {
|
|
|
153
188
|
),
|
|
154
189
|
);
|
|
155
190
|
|
|
191
|
+
expect(versionResponse.status).toBe(200);
|
|
192
|
+
await expect(versionResponse.json()).resolves.toEqual({
|
|
193
|
+
version: HOT_UPDATER_SERVER_VERSION,
|
|
194
|
+
});
|
|
156
195
|
expect(channelsResponse.status).toBe(200);
|
|
157
196
|
await expect(channelsResponse.json()).resolves.toEqual({
|
|
158
197
|
data: {
|
package/src/handler.ts
CHANGED
|
@@ -12,8 +12,7 @@ import type {
|
|
|
12
12
|
|
|
13
13
|
import { addRoute, createRouter, findRoute } from "./internalRouter";
|
|
14
14
|
import type { ChannelsResponse, PaginatedResult } from "./types";
|
|
15
|
-
|
|
16
|
-
declare const __VERSION__: string;
|
|
15
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version";
|
|
17
16
|
|
|
18
17
|
// Narrow API surface needed by the handler to avoid circular types
|
|
19
18
|
export interface HandlerAPI<TContext = unknown> {
|
|
@@ -60,9 +59,15 @@ export interface HandlerRoutes {
|
|
|
60
59
|
* @default true
|
|
61
60
|
*/
|
|
62
61
|
updateCheck?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Controls whether the `/version` endpoint is mounted.
|
|
64
|
+
* Useful for diagnostics and lightweight health/version checks.
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
version?: boolean;
|
|
63
68
|
/**
|
|
64
69
|
* Controls whether bundle management routes are mounted.
|
|
65
|
-
* This includes `/
|
|
70
|
+
* This includes `/api/bundles*`, which are used by the
|
|
66
71
|
* CLI `standaloneRepository` plugin.
|
|
67
72
|
* @default true
|
|
68
73
|
*/
|
|
@@ -85,7 +90,7 @@ class HandlerBadRequestError extends Error {
|
|
|
85
90
|
|
|
86
91
|
// Route handlers
|
|
87
92
|
const handleVersion: RouteHandler = async () => {
|
|
88
|
-
return new Response(JSON.stringify({ version:
|
|
93
|
+
return new Response(JSON.stringify({ version: HOT_UPDATER_SERVER_VERSION }), {
|
|
89
94
|
status: 200,
|
|
90
95
|
headers: { "Content-Type": "application/json" },
|
|
91
96
|
});
|
|
@@ -395,12 +400,17 @@ export function createHandler<TContext = unknown>(
|
|
|
395
400
|
) => Promise<Response> {
|
|
396
401
|
const basePath = options.basePath ?? "/api";
|
|
397
402
|
const updateCheckEnabled = options.routes?.updateCheck ?? true;
|
|
403
|
+
const versionEnabled = options.routes?.version ?? true;
|
|
398
404
|
const bundlesEnabled = options.routes?.bundles ?? true;
|
|
399
405
|
|
|
400
406
|
// Create and configure router
|
|
401
407
|
const router = createRouter();
|
|
402
408
|
|
|
403
409
|
// Register routes
|
|
410
|
+
if (versionEnabled) {
|
|
411
|
+
addRoute(router, "GET", "/version", "version");
|
|
412
|
+
}
|
|
413
|
+
|
|
404
414
|
if (updateCheckEnabled) {
|
|
405
415
|
addRoute(
|
|
406
416
|
router,
|
|
@@ -429,7 +439,6 @@ export function createHandler<TContext = unknown>(
|
|
|
429
439
|
}
|
|
430
440
|
|
|
431
441
|
if (bundlesEnabled) {
|
|
432
|
-
addRoute(router, "GET", "/version", "version");
|
|
433
442
|
addRoute(router, "GET", "/api/bundles/channels", "getChannels");
|
|
434
443
|
addRoute(router, "GET", "/api/bundles/:id", "getBundle");
|
|
435
444
|
addRoute(router, "GET", "/api/bundles", "getBundles");
|
package/src/index.ts
CHANGED
package/src/runtime.spec.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { createDatabasePlugin } from "@hot-updater/plugin-core";
|
|
|
9
9
|
import { describe, expect, expectTypeOf, it, vi } from "vitest";
|
|
10
10
|
|
|
11
11
|
import { createHotUpdater } from "./runtime";
|
|
12
|
+
import { HOT_UPDATER_SERVER_VERSION } from "./version";
|
|
12
13
|
|
|
13
14
|
const bundle: Bundle = {
|
|
14
15
|
id: "00000000-0000-0000-0000-000000000001",
|
|
@@ -382,6 +383,94 @@ describe("runtime createHotUpdater", () => {
|
|
|
382
383
|
expect(getBundles).toHaveBeenCalledWith(expect.any(Object), undefined);
|
|
383
384
|
});
|
|
384
385
|
|
|
386
|
+
it("keeps the version route mounted when bundle routes are disabled", async () => {
|
|
387
|
+
const database = createDatabasePlugin({
|
|
388
|
+
name: "version-enabled-plugin",
|
|
389
|
+
factory: () => ({
|
|
390
|
+
async getBundleById() {
|
|
391
|
+
return null;
|
|
392
|
+
},
|
|
393
|
+
async getBundles() {
|
|
394
|
+
return {
|
|
395
|
+
data: [],
|
|
396
|
+
pagination: {
|
|
397
|
+
hasNextPage: false,
|
|
398
|
+
hasPreviousPage: false,
|
|
399
|
+
currentPage: 1,
|
|
400
|
+
totalPages: 1,
|
|
401
|
+
total: 0,
|
|
402
|
+
},
|
|
403
|
+
};
|
|
404
|
+
},
|
|
405
|
+
async getChannels() {
|
|
406
|
+
return [];
|
|
407
|
+
},
|
|
408
|
+
async commitBundle() {},
|
|
409
|
+
}),
|
|
410
|
+
})({});
|
|
411
|
+
|
|
412
|
+
const hotUpdater = createHotUpdater({
|
|
413
|
+
database,
|
|
414
|
+
basePath: "/api/check-update",
|
|
415
|
+
routes: {
|
|
416
|
+
updateCheck: true,
|
|
417
|
+
bundles: false,
|
|
418
|
+
},
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
const response = await hotUpdater.handler(
|
|
422
|
+
new Request("https://updates.example.com/api/check-update/version"),
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
expect(response.status).toBe(200);
|
|
426
|
+
await expect(response.json()).resolves.toEqual({
|
|
427
|
+
version: HOT_UPDATER_SERVER_VERSION,
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("can disable the version route independently", async () => {
|
|
432
|
+
const database = createDatabasePlugin({
|
|
433
|
+
name: "version-disabled-plugin",
|
|
434
|
+
factory: () => ({
|
|
435
|
+
async getBundleById() {
|
|
436
|
+
return null;
|
|
437
|
+
},
|
|
438
|
+
async getBundles() {
|
|
439
|
+
return {
|
|
440
|
+
data: [],
|
|
441
|
+
pagination: {
|
|
442
|
+
hasNextPage: false,
|
|
443
|
+
hasPreviousPage: false,
|
|
444
|
+
currentPage: 1,
|
|
445
|
+
totalPages: 1,
|
|
446
|
+
total: 0,
|
|
447
|
+
},
|
|
448
|
+
};
|
|
449
|
+
},
|
|
450
|
+
async getChannels() {
|
|
451
|
+
return [];
|
|
452
|
+
},
|
|
453
|
+
async commitBundle() {},
|
|
454
|
+
}),
|
|
455
|
+
})({});
|
|
456
|
+
|
|
457
|
+
const hotUpdater = createHotUpdater({
|
|
458
|
+
database,
|
|
459
|
+
basePath: "/api/check-update",
|
|
460
|
+
routes: {
|
|
461
|
+
updateCheck: true,
|
|
462
|
+
version: false,
|
|
463
|
+
bundles: false,
|
|
464
|
+
},
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
const response = await hotUpdater.handler(
|
|
468
|
+
new Request("https://updates.example.com/api/check-update/version"),
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
expect(response.status).toBe(404);
|
|
472
|
+
});
|
|
473
|
+
|
|
385
474
|
it("clears pending plugin changes after a failed mutation commit", async () => {
|
|
386
475
|
const committedBundles = new Map<string, Bundle>();
|
|
387
476
|
let commitAttempt = 0;
|
package/src/runtime.ts
CHANGED
package/src/version.ts
ADDED