@hot-updater/server 0.31.4 → 0.33.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/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/_virtual/_rolldown/runtime.mjs +1 -1
- package/dist/db/createBundleDiff.cjs +19 -13
- package/dist/db/createBundleDiff.mjs +15 -9
- package/dist/db/index.cjs +7 -10
- package/dist/db/index.mjs +7 -10
- package/dist/db/pluginCore.cjs +136 -96
- package/dist/db/pluginCore.mjs +137 -97
- package/dist/db/requestBundleIdentityMap.cjs +29 -0
- package/dist/db/requestBundleIdentityMap.mjs +29 -0
- package/dist/db/schemaEnhancements.cjs +1 -1
- package/dist/db/types.d.cts +2 -1
- package/dist/db/types.d.mts +2 -1
- package/dist/db/updateArtifacts.cjs +6 -6
- package/dist/db/updateArtifacts.mjs +6 -6
- package/dist/handler.cjs +18 -8
- package/dist/handler.d.cts +9 -10
- package/dist/handler.d.mts +9 -10
- package/dist/handler.mjs +17 -7
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.d.cts +1 -1
- package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/index.d.mts +1 -1
- package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/query/index.d.cts +1 -1
- package/dist/node_modules/.pnpm/fumadb@0.2.2_drizzle-orm@0.44.7_@cloudflare_workers-types@4.20260313.1_@electric-sql_pg_c72c8c754becd21f6d6662e8fbd28e7f/node_modules/fumadb/dist/query/index.d.mts +1 -1
- package/dist/packages/server/package.cjs +1 -1
- package/dist/packages/server/package.mjs +1 -1
- package/dist/runtime.cjs +10 -12
- package/dist/runtime.mjs +10 -12
- package/package.json +7 -7
- package/src/db/createBundleDiff.spec.ts +3 -0
- package/src/db/createBundleDiff.ts +27 -21
- package/src/db/index.spec.ts +36 -0
- package/src/db/index.ts +6 -10
- package/src/db/pluginCore.spec.ts +443 -0
- package/src/db/pluginCore.ts +63 -7
- package/src/db/requestBundleIdentityMap.spec.ts +56 -0
- package/src/db/requestBundleIdentityMap.ts +61 -0
- package/src/db/types.ts +2 -0
- package/src/db/updateArtifacts.ts +8 -19
- package/src/handler-standalone.integration.spec.ts +12 -0
- package/src/handler.spec.ts +117 -19
- package/src/handler.ts +47 -21
- package/src/runtime.spec.ts +46 -4
- package/src/runtime.ts +10 -12
|
@@ -8,7 +8,10 @@ import {
|
|
|
8
8
|
type Bundle,
|
|
9
9
|
type ChangedAsset,
|
|
10
10
|
} from "@hot-updater/core";
|
|
11
|
-
import
|
|
11
|
+
import {
|
|
12
|
+
resolveManifestAssetStorageUri,
|
|
13
|
+
type HotUpdaterContext,
|
|
14
|
+
} from "@hot-updater/plugin-core";
|
|
12
15
|
|
|
13
16
|
type BundleManifest = {
|
|
14
17
|
bundleId: string;
|
|
@@ -74,21 +77,6 @@ const isBundleManifest = (value: unknown): value is BundleManifest => {
|
|
|
74
77
|
);
|
|
75
78
|
};
|
|
76
79
|
|
|
77
|
-
const createChildStorageUri = (
|
|
78
|
-
baseStorageUri: string,
|
|
79
|
-
relativePath: string,
|
|
80
|
-
) => {
|
|
81
|
-
const baseUrl = new URL(baseStorageUri);
|
|
82
|
-
const normalizedBasePath = baseUrl.pathname.replace(/\/+$/, "");
|
|
83
|
-
const relativeSegments = relativePath
|
|
84
|
-
.split("/")
|
|
85
|
-
.filter(Boolean)
|
|
86
|
-
.map((segment) => encodeURIComponent(segment));
|
|
87
|
-
|
|
88
|
-
baseUrl.pathname = `${normalizedBasePath}/${relativeSegments.join("/")}`;
|
|
89
|
-
return baseUrl.toString();
|
|
90
|
-
};
|
|
91
|
-
|
|
92
80
|
export const parseBundleMetadata = (
|
|
93
81
|
value: unknown,
|
|
94
82
|
): Bundle["metadata"] | undefined => {
|
|
@@ -213,10 +201,11 @@ async function resolveChangedAssets<TContext>({
|
|
|
213
201
|
|
|
214
202
|
const usesBrotliAsset = BR_COMPRESSED_ASSET_PATH_RE.test(assetPath);
|
|
215
203
|
const downloadPath = usesBrotliAsset ? `${assetPath}.br` : assetPath;
|
|
216
|
-
const storageUri =
|
|
204
|
+
const storageUri = resolveManifestAssetStorageUri({
|
|
217
205
|
assetBaseStorageUri,
|
|
218
|
-
downloadPath,
|
|
219
|
-
|
|
206
|
+
assetPath: downloadPath,
|
|
207
|
+
fileHash: asset.fileHash,
|
|
208
|
+
});
|
|
220
209
|
const patch =
|
|
221
210
|
patchDescriptor?.assetPath === assetPath ? patchDescriptor.patch : null;
|
|
222
211
|
|
|
@@ -34,6 +34,10 @@ const api = createHotUpdater({
|
|
|
34
34
|
provider: "postgresql",
|
|
35
35
|
}),
|
|
36
36
|
basePath: "/hot-updater",
|
|
37
|
+
routes: {
|
|
38
|
+
updateCheck: true,
|
|
39
|
+
bundles: true,
|
|
40
|
+
},
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
// Setup MSW server to intercept HTTP requests
|
|
@@ -341,6 +345,10 @@ describe("Handler <-> Standalone Repository Integration", () => {
|
|
|
341
345
|
provider: "postgresql",
|
|
342
346
|
}),
|
|
343
347
|
basePath: "/api/v2",
|
|
348
|
+
routes: {
|
|
349
|
+
updateCheck: true,
|
|
350
|
+
bundles: true,
|
|
351
|
+
},
|
|
344
352
|
});
|
|
345
353
|
|
|
346
354
|
// Setup MSW for custom basePath
|
|
@@ -411,6 +419,10 @@ describe("Handler <-> Standalone Repository Integration", () => {
|
|
|
411
419
|
const blobApi = createHotUpdater({
|
|
412
420
|
database: createInMemoryBlobDatabase(store),
|
|
413
421
|
basePath: "/blob-hot-updater",
|
|
422
|
+
routes: {
|
|
423
|
+
updateCheck: true,
|
|
424
|
+
bundles: true,
|
|
425
|
+
},
|
|
414
426
|
});
|
|
415
427
|
const handleBlobRequest = async (request: Request) => {
|
|
416
428
|
const response = await blobApi.handler(request);
|
package/src/handler.spec.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Bundle, NIL_UUID } from "@hot-updater/core";
|
|
2
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { createHandler, type HandlerAPI } from "./handler";
|
|
4
|
+
import { createHandler, type HandlerAPI, type HandlerRoutes } from "./handler";
|
|
5
5
|
import { HOT_UPDATER_SERVER_VERSION } from "./version";
|
|
6
6
|
|
|
7
7
|
const NEXT_SDK_VERSION_FOR_TEST = "0.31.0";
|
|
@@ -51,6 +51,19 @@ const createApi = () =>
|
|
|
51
51
|
deleteBundleById: vi.fn<HandlerAPI<TestContext>["deleteBundleById"]>(),
|
|
52
52
|
}) satisfies HandlerAPI<TestContext>;
|
|
53
53
|
|
|
54
|
+
const createManagementHandler = (
|
|
55
|
+
api: HandlerAPI<TestContext>,
|
|
56
|
+
routes: Partial<HandlerRoutes> = {},
|
|
57
|
+
) =>
|
|
58
|
+
createHandler(api, {
|
|
59
|
+
basePath: "/hot-updater",
|
|
60
|
+
routes: {
|
|
61
|
+
updateCheck: true,
|
|
62
|
+
bundles: true,
|
|
63
|
+
...routes,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
54
67
|
describe("createHandler", () => {
|
|
55
68
|
it("supports the app-version route without a cohort segment", async () => {
|
|
56
69
|
const api = createApi();
|
|
@@ -218,44 +231,113 @@ describe("createHandler", () => {
|
|
|
218
231
|
expect(updateResponse.status).toBe(200);
|
|
219
232
|
});
|
|
220
233
|
|
|
221
|
-
it("
|
|
234
|
+
it("does not mount bundle routes by default", async () => {
|
|
235
|
+
const api = createApi();
|
|
236
|
+
const handler = createHandler(api, { basePath: "/hot-updater" });
|
|
237
|
+
|
|
238
|
+
const versionResponse = await handler(
|
|
239
|
+
new Request("http://localhost/hot-updater/version"),
|
|
240
|
+
);
|
|
241
|
+
const bundlesResponse = await handler(
|
|
242
|
+
new Request("http://localhost/hot-updater/api/bundles"),
|
|
243
|
+
);
|
|
244
|
+
const updateResponse = await handler(
|
|
245
|
+
new Request(
|
|
246
|
+
"http://localhost/hot-updater/app-version/ios/1.0.0/production/default/default",
|
|
247
|
+
),
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
expect(versionResponse.status).toBe(200);
|
|
251
|
+
expect(bundlesResponse.status).toBe(404);
|
|
252
|
+
expect(updateResponse.status).toBe(200);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("mounts bundle routes when explicitly enabled", async () => {
|
|
222
256
|
const api = createApi();
|
|
257
|
+
api.getBundles.mockResolvedValueOnce({
|
|
258
|
+
data: [],
|
|
259
|
+
pagination: {
|
|
260
|
+
total: 0,
|
|
261
|
+
hasNextPage: false,
|
|
262
|
+
hasPreviousPage: false,
|
|
263
|
+
currentPage: 1,
|
|
264
|
+
totalPages: 0,
|
|
265
|
+
},
|
|
266
|
+
});
|
|
223
267
|
const handler = createHandler(api, {
|
|
224
268
|
basePath: "/hot-updater",
|
|
225
269
|
routes: {
|
|
226
270
|
updateCheck: true,
|
|
227
|
-
|
|
228
|
-
bundles: false,
|
|
271
|
+
bundles: true,
|
|
229
272
|
},
|
|
230
273
|
});
|
|
231
274
|
|
|
232
|
-
const
|
|
233
|
-
new Request("http://localhost/hot-updater/version"),
|
|
234
|
-
);
|
|
235
|
-
const bundlesResponse = await handler(
|
|
275
|
+
const response = await handler(
|
|
236
276
|
new Request("http://localhost/hot-updater/api/bundles"),
|
|
237
277
|
);
|
|
278
|
+
|
|
279
|
+
expect(response.status).toBe(200);
|
|
280
|
+
expect(api.getBundles).toHaveBeenCalledWith(
|
|
281
|
+
{
|
|
282
|
+
cursor: undefined,
|
|
283
|
+
limit: 50,
|
|
284
|
+
page: undefined,
|
|
285
|
+
where: {},
|
|
286
|
+
},
|
|
287
|
+
undefined,
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("keeps update-check routes mounted for partial runtime route config", async () => {
|
|
292
|
+
const api = createApi();
|
|
293
|
+
const handler = createHandler(api, {
|
|
294
|
+
basePath: "/hot-updater",
|
|
295
|
+
routes: JSON.parse('{"bundles":true}') as HandlerRoutes,
|
|
296
|
+
});
|
|
297
|
+
|
|
238
298
|
const updateResponse = await handler(
|
|
239
299
|
new Request(
|
|
240
300
|
"http://localhost/hot-updater/app-version/ios/1.0.0/production/default/default",
|
|
241
301
|
),
|
|
242
302
|
);
|
|
243
303
|
|
|
244
|
-
expect(versionResponse.status).toBe(404);
|
|
245
|
-
expect(bundlesResponse.status).toBe(404);
|
|
246
304
|
expect(updateResponse.status).toBe(200);
|
|
247
305
|
});
|
|
248
306
|
|
|
249
|
-
it("
|
|
307
|
+
it("keeps the version route mounted when update-check routes are disabled", async () => {
|
|
250
308
|
const api = createApi();
|
|
251
309
|
const handler = createHandler(api, {
|
|
252
310
|
basePath: "/hot-updater",
|
|
253
311
|
routes: {
|
|
254
312
|
updateCheck: false,
|
|
255
|
-
bundles:
|
|
313
|
+
bundles: false,
|
|
256
314
|
},
|
|
257
315
|
});
|
|
258
316
|
|
|
317
|
+
const versionResponse = await handler(
|
|
318
|
+
new Request("http://localhost/hot-updater/version"),
|
|
319
|
+
);
|
|
320
|
+
const bundlesResponse = await handler(
|
|
321
|
+
new Request("http://localhost/hot-updater/api/bundles"),
|
|
322
|
+
);
|
|
323
|
+
const updateResponse = await handler(
|
|
324
|
+
new Request(
|
|
325
|
+
"http://localhost/hot-updater/app-version/ios/1.0.0/production/default/default",
|
|
326
|
+
),
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
expect(versionResponse.status).toBe(200);
|
|
330
|
+
await expect(versionResponse.json()).resolves.toEqual({
|
|
331
|
+
version: HOT_UPDATER_SERVER_VERSION,
|
|
332
|
+
});
|
|
333
|
+
expect(bundlesResponse.status).toBe(404);
|
|
334
|
+
expect(updateResponse.status).toBe(404);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("can mount bundle routes without update-check routes", async () => {
|
|
338
|
+
const api = createApi();
|
|
339
|
+
const handler = createManagementHandler(api, { updateCheck: false });
|
|
340
|
+
|
|
259
341
|
const versionResponse = await handler(
|
|
260
342
|
new Request("http://localhost/hot-updater/version"),
|
|
261
343
|
);
|
|
@@ -294,7 +376,7 @@ describe("createHandler", () => {
|
|
|
294
376
|
totalPages: 26,
|
|
295
377
|
},
|
|
296
378
|
});
|
|
297
|
-
const handler =
|
|
379
|
+
const handler = createManagementHandler(api);
|
|
298
380
|
|
|
299
381
|
const response = await handler(
|
|
300
382
|
new Request(
|
|
@@ -339,7 +421,7 @@ describe("createHandler", () => {
|
|
|
339
421
|
totalPages: 1,
|
|
340
422
|
},
|
|
341
423
|
});
|
|
342
|
-
const handler =
|
|
424
|
+
const handler = createManagementHandler(api);
|
|
343
425
|
|
|
344
426
|
const response = await handler(
|
|
345
427
|
new Request(
|
|
@@ -382,7 +464,7 @@ describe("createHandler", () => {
|
|
|
382
464
|
previousCursor: "bundle-9",
|
|
383
465
|
},
|
|
384
466
|
});
|
|
385
|
-
const handler =
|
|
467
|
+
const handler = createManagementHandler(api);
|
|
386
468
|
|
|
387
469
|
const response = await handler(
|
|
388
470
|
new Request(
|
|
@@ -421,7 +503,7 @@ describe("createHandler", () => {
|
|
|
421
503
|
previousCursor: null,
|
|
422
504
|
},
|
|
423
505
|
});
|
|
424
|
-
const handler =
|
|
506
|
+
const handler = createManagementHandler(api);
|
|
425
507
|
|
|
426
508
|
const response = await handler(
|
|
427
509
|
new Request(
|
|
@@ -448,7 +530,7 @@ describe("createHandler", () => {
|
|
|
448
530
|
|
|
449
531
|
it("returns 400 when bundle list requests still send offset pagination", async () => {
|
|
450
532
|
const api = createApi();
|
|
451
|
-
const handler =
|
|
533
|
+
const handler = createManagementHandler(api);
|
|
452
534
|
|
|
453
535
|
const response = await handler(
|
|
454
536
|
new Request(
|
|
@@ -478,7 +560,7 @@ describe("createHandler", () => {
|
|
|
478
560
|
previousCursor: "bundle-9",
|
|
479
561
|
},
|
|
480
562
|
});
|
|
481
|
-
const handler =
|
|
563
|
+
const handler = createManagementHandler(api);
|
|
482
564
|
|
|
483
565
|
const response = await handler(
|
|
484
566
|
new Request(
|
|
@@ -505,7 +587,7 @@ describe("createHandler", () => {
|
|
|
505
587
|
|
|
506
588
|
it("returns 400 when bundle list requests send an invalid page", async () => {
|
|
507
589
|
const api = createApi();
|
|
508
|
-
const handler =
|
|
590
|
+
const handler = createManagementHandler(api);
|
|
509
591
|
|
|
510
592
|
const response = await handler(
|
|
511
593
|
new Request("http://localhost/hot-updater/api/bundles?limit=20&page=0"),
|
|
@@ -518,6 +600,22 @@ describe("createHandler", () => {
|
|
|
518
600
|
expect(api.getBundles).not.toHaveBeenCalled();
|
|
519
601
|
});
|
|
520
602
|
|
|
603
|
+
it("returns 400 when bundle list limit exceeds the maximum", async () => {
|
|
604
|
+
const api = createApi();
|
|
605
|
+
const handler = createManagementHandler(api);
|
|
606
|
+
|
|
607
|
+
const response = await handler(
|
|
608
|
+
new Request("http://localhost/hot-updater/api/bundles?limit=101"),
|
|
609
|
+
);
|
|
610
|
+
|
|
611
|
+
expect(response.status).toBe(400);
|
|
612
|
+
await expect(response.json()).resolves.toEqual({
|
|
613
|
+
error:
|
|
614
|
+
"The 'limit' query parameter must be a positive integer between 1 and 100.",
|
|
615
|
+
});
|
|
616
|
+
expect(api.getBundles).not.toHaveBeenCalled();
|
|
617
|
+
});
|
|
618
|
+
|
|
521
619
|
it("returns 400 when the platform route parameter is invalid", async () => {
|
|
522
620
|
const api = createApi();
|
|
523
621
|
const handler = createHandler(api, { basePath: "/hot-updater" });
|
package/src/handler.ts
CHANGED
|
@@ -52,28 +52,27 @@ export interface HandlerOptions {
|
|
|
52
52
|
* @default "/api"
|
|
53
53
|
*/
|
|
54
54
|
basePath?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Route groups to mount. Omit this option to use the default route groups.
|
|
57
|
+
* When provided, both route groups must be specified explicitly.
|
|
58
|
+
* The `/version` endpoint is always mounted for diagnostics.
|
|
59
|
+
*/
|
|
55
60
|
routes?: HandlerRoutes;
|
|
56
61
|
}
|
|
57
62
|
|
|
58
63
|
export interface HandlerRoutes {
|
|
59
64
|
/**
|
|
60
65
|
* Controls whether update-check routes are mounted.
|
|
61
|
-
*
|
|
66
|
+
* Defaults to `true` only when `routes` is omitted.
|
|
62
67
|
*/
|
|
63
|
-
updateCheck
|
|
64
|
-
/**
|
|
65
|
-
* Controls whether the `/version` endpoint is mounted.
|
|
66
|
-
* Useful for diagnostics and lightweight health/version checks.
|
|
67
|
-
* @default true
|
|
68
|
-
*/
|
|
69
|
-
version?: boolean;
|
|
68
|
+
updateCheck: boolean;
|
|
70
69
|
/**
|
|
71
70
|
* Controls whether bundle management routes are mounted.
|
|
72
71
|
* This includes `/api/bundles*`, which are used by the
|
|
73
72
|
* CLI `standaloneRepository` plugin.
|
|
74
|
-
*
|
|
73
|
+
* Defaults to `false` only when `routes` is omitted.
|
|
75
74
|
*/
|
|
76
|
-
bundles
|
|
75
|
+
bundles: boolean;
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
type RouteHandler<TContext = unknown> = (
|
|
@@ -92,6 +91,8 @@ class HandlerBadRequestError extends Error {
|
|
|
92
91
|
|
|
93
92
|
const SDK_VERSION_HEADER = "Hot-Updater-SDK-Version";
|
|
94
93
|
const EXPLICIT_NO_UPDATE_MIN_SDK_VERSION = "0.31.0";
|
|
94
|
+
const DEFAULT_BUNDLE_LIST_LIMIT = 50;
|
|
95
|
+
const MAX_BUNDLE_LIST_LIMIT = 100;
|
|
95
96
|
|
|
96
97
|
const supportsExplicitNoUpdateResponse = (request: Request) => {
|
|
97
98
|
const sdkVersion = request.headers.get(SDK_VERSION_HEADER)?.trim();
|
|
@@ -191,6 +192,27 @@ const parseStringArraySearchParam = (url: URL, key: string) => {
|
|
|
191
192
|
return values.length > 0 ? values : undefined;
|
|
192
193
|
};
|
|
193
194
|
|
|
195
|
+
const parsePositiveIntegerSearchParam = (
|
|
196
|
+
url: URL,
|
|
197
|
+
key: string,
|
|
198
|
+
defaultValue: number,
|
|
199
|
+
maxValue: number,
|
|
200
|
+
): number => {
|
|
201
|
+
const value = url.searchParams.get(key);
|
|
202
|
+
if (value === null) {
|
|
203
|
+
return defaultValue;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const parsed = Number(value);
|
|
207
|
+
if (!Number.isInteger(parsed) || parsed < 1 || parsed > maxValue) {
|
|
208
|
+
throw new HandlerBadRequestError(
|
|
209
|
+
`The '${key}' query parameter must be a positive integer between 1 and ${maxValue}.`,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return parsed;
|
|
214
|
+
};
|
|
215
|
+
|
|
194
216
|
const requirePlatformParam = (params: Record<string, string>): Platform => {
|
|
195
217
|
const platform = requireRouteParam(params, "platform");
|
|
196
218
|
|
|
@@ -317,7 +339,12 @@ const handleGetBundles: RouteHandler = async (
|
|
|
317
339
|
const url = new URL(request.url);
|
|
318
340
|
const channel = url.searchParams.get("channel") ?? undefined;
|
|
319
341
|
const platform = url.searchParams.get("platform");
|
|
320
|
-
const limit =
|
|
342
|
+
const limit = parsePositiveIntegerSearchParam(
|
|
343
|
+
url,
|
|
344
|
+
"limit",
|
|
345
|
+
DEFAULT_BUNDLE_LIST_LIMIT,
|
|
346
|
+
MAX_BUNDLE_LIST_LIMIT,
|
|
347
|
+
);
|
|
321
348
|
const pageParam = url.searchParams.get("page");
|
|
322
349
|
const offset = url.searchParams.get("offset");
|
|
323
350
|
const after = url.searchParams.get("after") ?? undefined;
|
|
@@ -511,19 +538,18 @@ export function createHandler<TContext = unknown>(
|
|
|
511
538
|
context?: HotUpdaterContext<TContext>,
|
|
512
539
|
) => Promise<Response> {
|
|
513
540
|
const basePath = options.basePath ?? "/api";
|
|
514
|
-
const
|
|
515
|
-
|
|
516
|
-
|
|
541
|
+
const routeOptions = {
|
|
542
|
+
updateCheck: options.routes?.updateCheck ?? true,
|
|
543
|
+
bundles: options.routes?.bundles ?? false,
|
|
544
|
+
};
|
|
517
545
|
|
|
518
546
|
// Create and configure router
|
|
519
547
|
const router = createRouter();
|
|
520
548
|
|
|
521
549
|
// Register routes
|
|
522
|
-
|
|
523
|
-
addRoute(router, "GET", "/version", "version");
|
|
524
|
-
}
|
|
550
|
+
addRoute(router, "GET", "/version", "version");
|
|
525
551
|
|
|
526
|
-
if (
|
|
552
|
+
if (routeOptions.updateCheck) {
|
|
527
553
|
addRoute(
|
|
528
554
|
router,
|
|
529
555
|
"GET",
|
|
@@ -550,7 +576,7 @@ export function createHandler<TContext = unknown>(
|
|
|
550
576
|
);
|
|
551
577
|
}
|
|
552
578
|
|
|
553
|
-
if (
|
|
579
|
+
if (routeOptions.bundles) {
|
|
554
580
|
addRoute(router, "GET", "/api/bundles/channels", "getChannels");
|
|
555
581
|
addRoute(router, "GET", "/api/bundles/:id", "getBundle");
|
|
556
582
|
addRoute(router, "GET", "/api/bundles", "getBundles");
|
|
@@ -583,8 +609,8 @@ export function createHandler<TContext = unknown>(
|
|
|
583
609
|
});
|
|
584
610
|
}
|
|
585
611
|
|
|
586
|
-
|
|
587
|
-
const handler = routes[
|
|
612
|
+
const routeName = match.data as string;
|
|
613
|
+
const handler = routes[routeName] as RouteHandler<TContext>;
|
|
588
614
|
if (!handler) {
|
|
589
615
|
return new Response(JSON.stringify({ error: "Handler not found" }), {
|
|
590
616
|
status: 500,
|
package/src/runtime.spec.ts
CHANGED
|
@@ -80,6 +80,7 @@ describe("runtime createHotUpdater", () => {
|
|
|
80
80
|
node: {
|
|
81
81
|
delete: vi.fn(),
|
|
82
82
|
downloadFile: vi.fn(),
|
|
83
|
+
exists: vi.fn(async () => false),
|
|
83
84
|
upload: vi.fn(),
|
|
84
85
|
},
|
|
85
86
|
},
|
|
@@ -660,7 +661,7 @@ describe("runtime createHotUpdater", () => {
|
|
|
660
661
|
});
|
|
661
662
|
});
|
|
662
663
|
|
|
663
|
-
it("
|
|
664
|
+
it("keeps the version route mounted when update-check routes are disabled", async () => {
|
|
664
665
|
const database = createDatabasePlugin({
|
|
665
666
|
name: "version-disabled-plugin",
|
|
666
667
|
factory: () => ({
|
|
@@ -690,8 +691,7 @@ describe("runtime createHotUpdater", () => {
|
|
|
690
691
|
database,
|
|
691
692
|
basePath: "/api/check-update",
|
|
692
693
|
routes: {
|
|
693
|
-
updateCheck:
|
|
694
|
-
version: false,
|
|
694
|
+
updateCheck: false,
|
|
695
695
|
bundles: false,
|
|
696
696
|
},
|
|
697
697
|
});
|
|
@@ -700,7 +700,49 @@ describe("runtime createHotUpdater", () => {
|
|
|
700
700
|
new Request("https://updates.example.com/api/check-update/version"),
|
|
701
701
|
);
|
|
702
702
|
|
|
703
|
-
expect(response.status).toBe(
|
|
703
|
+
expect(response.status).toBe(200);
|
|
704
|
+
await expect(response.json()).resolves.toEqual({
|
|
705
|
+
version: HOT_UPDATER_SERVER_VERSION,
|
|
706
|
+
});
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
it("keeps optional maintenance capabilities lazy", () => {
|
|
710
|
+
const factory = vi.fn(() => ({
|
|
711
|
+
async getBundleById() {
|
|
712
|
+
return null;
|
|
713
|
+
},
|
|
714
|
+
async getBundles() {
|
|
715
|
+
return {
|
|
716
|
+
data: [],
|
|
717
|
+
pagination: {
|
|
718
|
+
hasNextPage: false,
|
|
719
|
+
hasPreviousPage: false,
|
|
720
|
+
currentPage: 1,
|
|
721
|
+
totalPages: 1,
|
|
722
|
+
total: 0,
|
|
723
|
+
},
|
|
724
|
+
};
|
|
725
|
+
},
|
|
726
|
+
async getChannels() {
|
|
727
|
+
return [];
|
|
728
|
+
},
|
|
729
|
+
async commitBundle() {},
|
|
730
|
+
}));
|
|
731
|
+
const database = createDatabasePlugin({
|
|
732
|
+
name: "lazyRuntimePlugin",
|
|
733
|
+
factory,
|
|
734
|
+
})({});
|
|
735
|
+
|
|
736
|
+
const hotUpdater = createHotUpdater({
|
|
737
|
+
database,
|
|
738
|
+
basePath: "/api/check-update",
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
expect(factory).not.toHaveBeenCalled();
|
|
742
|
+
expect(hotUpdater.diagnostics).toBeUndefined();
|
|
743
|
+
expect(factory).not.toHaveBeenCalled();
|
|
744
|
+
expect(hotUpdater.diagnostics).toBeUndefined();
|
|
745
|
+
expect(factory).not.toHaveBeenCalled();
|
|
704
746
|
});
|
|
705
747
|
|
|
706
748
|
it("clears pending plugin changes after a failed mutation commit", async () => {
|
package/src/runtime.ts
CHANGED
|
@@ -73,14 +73,10 @@ export function createHotUpdater<TContext = unknown>(
|
|
|
73
73
|
: { readStorageText },
|
|
74
74
|
);
|
|
75
75
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
routes: options.routes,
|
|
81
|
-
}),
|
|
82
|
-
adapterName: core.adapterName,
|
|
83
|
-
};
|
|
76
|
+
const internalHandler = createHandler(core.api, {
|
|
77
|
+
basePath,
|
|
78
|
+
routes: options.routes,
|
|
79
|
+
});
|
|
84
80
|
|
|
85
81
|
// Some framework adapters strip the mounted base path or pass extra
|
|
86
82
|
// bindings/execution context arguments. Ignore those extras here so the
|
|
@@ -91,17 +87,19 @@ export function createHotUpdater<TContext = unknown>(
|
|
|
91
87
|
...extraArgs: unknown[]
|
|
92
88
|
) => {
|
|
93
89
|
if (extraArgs.length > 0) {
|
|
94
|
-
return
|
|
90
|
+
return internalHandler(request);
|
|
95
91
|
}
|
|
96
92
|
|
|
97
|
-
return
|
|
93
|
+
return internalHandler(request, context);
|
|
98
94
|
};
|
|
99
95
|
|
|
100
|
-
|
|
101
|
-
...api,
|
|
96
|
+
const api = {
|
|
102
97
|
basePath,
|
|
98
|
+
adapterName: core.adapterName,
|
|
103
99
|
handler,
|
|
104
100
|
};
|
|
101
|
+
Object.defineProperties(api, Object.getOwnPropertyDescriptors(core.api));
|
|
102
|
+
return api as HotUpdaterAPI<TContext>;
|
|
105
103
|
}
|
|
106
104
|
|
|
107
105
|
export { createHandler };
|