@hot-updater/standalone 1.2.0-rc.4 → 1.2.0-rc.41
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 +123 -17
- package/dist/index.d.cts +23 -4
- package/dist/index.d.mts +23 -4
- package/dist/index.mjs +124 -18
- package/package.json +4 -9
package/dist/index.cjs
CHANGED
|
@@ -12,11 +12,13 @@ var StandaloneDatabaseError = class extends Error {
|
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
15
|
+
/** `headers` with each lazy value resolved. */
|
|
16
|
+
const resolveHeaders = async (headers = {}) => Object.fromEntries(await Promise.all(Object.entries(headers).map(async ([name, value]) => [name, await (0, _hot_updater_plugin_core.resolveLazy)(value)])));
|
|
15
17
|
const createStandaloneHttp = (config) => {
|
|
16
18
|
const buildUrl = (path) => `${config.baseUrl.replace(/\/+$/, "")}${path}`;
|
|
17
|
-
const headers = (routeHeaders) => ({
|
|
19
|
+
const headers = async (routeHeaders) => ({
|
|
18
20
|
"Content-Type": "application/json",
|
|
19
|
-
...config.commonHeaders,
|
|
21
|
+
...await resolveHeaders(config.commonHeaders),
|
|
20
22
|
...routeHeaders
|
|
21
23
|
});
|
|
22
24
|
const requestFailed = async (response) => {
|
|
@@ -74,15 +76,22 @@ const refusal = (status, value, fallback) => {
|
|
|
74
76
|
}
|
|
75
77
|
return new StandaloneDatabaseError("request-failed", message, status);
|
|
76
78
|
};
|
|
77
|
-
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion }) => ({
|
|
79
|
+
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion, sandbox }) => ({
|
|
78
80
|
platform,
|
|
79
81
|
channel,
|
|
80
|
-
...fingerprintHash === null ? { appVersion } : { fingerprintHash }
|
|
82
|
+
...fingerprintHash === null ? { appVersion } : { fingerprintHash },
|
|
83
|
+
...sandbox === void 0 || sandbox === null ? {} : {
|
|
84
|
+
sandboxAppId: sandbox.appId,
|
|
85
|
+
sandboxUrlScheme: sandbox.urlScheme,
|
|
86
|
+
artifactKind: sandbox.artifactKind,
|
|
87
|
+
distribution: sandbox.distribution
|
|
88
|
+
}
|
|
81
89
|
});
|
|
82
|
-
const keysetParams = ({ order, after, limit }) => ({
|
|
90
|
+
const keysetParams = ({ order, after, through, limit }) => ({
|
|
83
91
|
limit: String(limit),
|
|
84
92
|
...order === void 0 ? {} : { order },
|
|
85
|
-
...after === void 0 ? {} : { cursor: after }
|
|
93
|
+
...after === void 0 ? {} : { cursor: after },
|
|
94
|
+
...through === void 0 ? {} : { through }
|
|
86
95
|
});
|
|
87
96
|
const filterParams = (filter) => {
|
|
88
97
|
switch (filter.kind) {
|
|
@@ -108,7 +117,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
108
117
|
const http = createStandaloneHttp(config);
|
|
109
118
|
let checked;
|
|
110
119
|
const checkProtocol = async () => {
|
|
111
|
-
const response = await fetch(http.buildUrl("/version"), { headers: http.headers({ "Cache-Control": "no-cache" }) });
|
|
120
|
+
const response = await fetch(http.buildUrl("/version"), { headers: await http.headers({ "Cache-Control": "no-cache" }) });
|
|
112
121
|
const body = response.status === 404 ? {} : await http.parseJson(response);
|
|
113
122
|
const protocol = isRecord(body) ? body.adminProtocol : void 0;
|
|
114
123
|
if (typeof protocol !== "number" || protocol < 2) throw new StandaloneDatabaseError("request-failed", `The server at ${config.baseUrl} does not report Hot Updater admin API protocol 2 at /version. Set baseUrl to the path where the server mounts handlers.admin, such as https://example.com/hot-updater/admin.`, response.status);
|
|
@@ -125,7 +134,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
125
134
|
for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
|
|
126
135
|
const response = await fetch(url, {
|
|
127
136
|
method,
|
|
128
|
-
headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
137
|
+
headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
129
138
|
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
130
139
|
});
|
|
131
140
|
if (response.status === 204) return null;
|
|
@@ -188,11 +197,17 @@ const createStandaloneCoreApi = (config) => {
|
|
|
188
197
|
const row = await call("GET", "/native-builds/latest", {
|
|
189
198
|
query: {
|
|
190
199
|
...nativeBuildScopeParams(scope),
|
|
191
|
-
...buildKey === void 0 ? {} : { buildKey }
|
|
200
|
+
...buildKey === void 0 ? {} : { buildKey },
|
|
201
|
+
...options?.storeBuild ? { storeBuild: "true" } : {},
|
|
202
|
+
...options?.builtInOlderThan === void 0 ? {} : { builtInOlderThan: options.builtInOlderThan }
|
|
192
203
|
},
|
|
193
204
|
requiredRoute: "native build"
|
|
194
205
|
});
|
|
195
|
-
|
|
206
|
+
if (buildKey !== void 0 && row?.build_key !== buildKey) return null;
|
|
207
|
+
if (options?.storeBuild && row?.is_store_build !== true) return null;
|
|
208
|
+
const sandbox = scope.sandbox;
|
|
209
|
+
if (sandbox && row !== null && (row.is_sandbox !== true || row.artifact_kind !== sandbox.artifactKind || row.sandbox_url_scheme !== sandbox.urlScheme)) return null;
|
|
210
|
+
return row;
|
|
196
211
|
},
|
|
197
212
|
listNativeBuilds: ({ channelId, ...input }) => list("/native-builds", {
|
|
198
213
|
...keysetParams(input),
|
|
@@ -236,6 +251,52 @@ const createStandaloneCoreApi = (config) => {
|
|
|
236
251
|
body: submission,
|
|
237
252
|
requiredRoute: "native build submission"
|
|
238
253
|
}),
|
|
254
|
+
markNativeBuild: (id, mark) => call("POST", `/native-builds/${encode(id)}/store-build`, {
|
|
255
|
+
body: mark,
|
|
256
|
+
requiredRoute: "native build store mark"
|
|
257
|
+
}),
|
|
258
|
+
listIosDevices: async ({ status, ...input }) => await call("GET", "/ios-devices", {
|
|
259
|
+
query: {
|
|
260
|
+
...keysetParams(input),
|
|
261
|
+
...status === void 0 ? {} : { status }
|
|
262
|
+
},
|
|
263
|
+
requiredRoute: "iOS device registry"
|
|
264
|
+
}) ?? [],
|
|
265
|
+
findIosDevice: (udid) => call("GET", `/ios-devices/udid/${encode(udid)}`, { requiredRoute: "iOS device registry" }),
|
|
266
|
+
requestIosDevice: async (input) => await call("POST", "/ios-devices", {
|
|
267
|
+
body: input,
|
|
268
|
+
requiredRoute: "iOS device registry"
|
|
269
|
+
}),
|
|
270
|
+
approveIosDevice: (id, input) => call("POST", `/ios-devices/${encode(id)}/approval`, {
|
|
271
|
+
body: input,
|
|
272
|
+
requiredRoute: "iOS device registry"
|
|
273
|
+
}),
|
|
274
|
+
renameIosDevice: (id, name) => call("PATCH", `/ios-devices/${encode(id)}`, {
|
|
275
|
+
body: { name },
|
|
276
|
+
requiredRoute: "iOS device registry"
|
|
277
|
+
}),
|
|
278
|
+
recordIosDeviceOutcome: ({ id, ...input }) => call("POST", `/ios-devices/${encode(id)}/outcome`, {
|
|
279
|
+
body: input,
|
|
280
|
+
requiredRoute: "iOS device registry"
|
|
281
|
+
}),
|
|
282
|
+
markIosDevicesInBuild: async (input) => {
|
|
283
|
+
await request("POST", "/ios-devices/in-build", {
|
|
284
|
+
body: input,
|
|
285
|
+
requiredRoute: "iOS device registry"
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
findIosDeviceAccount: () => call("GET", "/ios-devices/account", { requiredRoute: "iOS device registry" }),
|
|
289
|
+
claimIosDeviceAccount: async (issuerId) => await call("POST", "/ios-devices/account", {
|
|
290
|
+
body: { issuerId },
|
|
291
|
+
requiredRoute: "iOS device registry"
|
|
292
|
+
}),
|
|
293
|
+
deleteIosDevice: (id, only) => call("DELETE", `/ios-devices/${encode(id)}`, {
|
|
294
|
+
query: {
|
|
295
|
+
...only?.status === void 0 ? {} : { status: only.status },
|
|
296
|
+
...only?.requestedBy === void 0 ? {} : { requestedBy: only.requestedBy }
|
|
297
|
+
},
|
|
298
|
+
requiredRoute: "iOS device registry"
|
|
299
|
+
}),
|
|
239
300
|
deleteNativeBuild: async (id) => await call("DELETE", `/native-builds/${encode(id)}`, { requiredRoute: "native build deletion" })
|
|
240
301
|
};
|
|
241
302
|
};
|
|
@@ -252,8 +313,8 @@ const standaloneRepository = (config) => {
|
|
|
252
313
|
return Object.freeze({
|
|
253
314
|
name: "standalone-repository",
|
|
254
315
|
core: createStandaloneCoreApi(config),
|
|
255
|
-
fetchAdmin: (path, init = {}) => {
|
|
256
|
-
const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
|
|
316
|
+
fetchAdmin: async (path, init = {}) => {
|
|
317
|
+
const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
|
|
257
318
|
new Headers(init.headers).forEach((value, name) => {
|
|
258
319
|
headers.set(name, value);
|
|
259
320
|
});
|
|
@@ -270,8 +331,12 @@ const defaultRoutes = {
|
|
|
270
331
|
put: () => ({ path: "/upload" }),
|
|
271
332
|
get: () => ({ path: "/get" }),
|
|
272
333
|
exists: () => ({ path: "/exists" }),
|
|
273
|
-
delete: () => ({ path: "/delete" })
|
|
334
|
+
delete: () => ({ path: "/delete" }),
|
|
335
|
+
listObjects: () => ({ path: "/list" }),
|
|
336
|
+
deleteObjects: () => ({ path: "/delete-objects" })
|
|
274
337
|
};
|
|
338
|
+
/** Keys sent in one `deleteObjects` request. */
|
|
339
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
275
340
|
const createRoute = (defaultRoute, customRoute) => ({
|
|
276
341
|
path: customRoute?.path ?? defaultRoute.path,
|
|
277
342
|
headers: {
|
|
@@ -280,8 +345,8 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
280
345
|
}
|
|
281
346
|
});
|
|
282
347
|
const standaloneStorage = (config) => {
|
|
283
|
-
const getHeaders = (routeHeaders) => ({
|
|
284
|
-
...config.commonHeaders,
|
|
348
|
+
const getHeaders = async (routeHeaders) => ({
|
|
349
|
+
...await resolveHeaders(config.commonHeaders),
|
|
285
350
|
...routeHeaders
|
|
286
351
|
});
|
|
287
352
|
const resolveRoute = (name, args) => {
|
|
@@ -289,6 +354,14 @@ const standaloneStorage = (config) => {
|
|
|
289
354
|
const custom = config.routes?.[name];
|
|
290
355
|
return createRoute(fallback(...args), custom?.(...args));
|
|
291
356
|
};
|
|
357
|
+
const postJson = async (path, headers, body) => fetch(`${config.baseUrl}${path}`, {
|
|
358
|
+
method: "POST",
|
|
359
|
+
headers: {
|
|
360
|
+
"content-type": "application/json",
|
|
361
|
+
...await getHeaders(headers)
|
|
362
|
+
},
|
|
363
|
+
body: JSON.stringify(body)
|
|
364
|
+
});
|
|
292
365
|
const requestStorageUri = async (routeName, storageUri) => {
|
|
293
366
|
(0, _hot_updater_plugin_core.parseStorageUri)(storageUri, config.protocol);
|
|
294
367
|
const { path, headers } = resolveRoute(routeName, [{ storageUri }]);
|
|
@@ -296,7 +369,7 @@ const standaloneStorage = (config) => {
|
|
|
296
369
|
method: routeName === "delete" ? "DELETE" : "POST",
|
|
297
370
|
headers: {
|
|
298
371
|
"content-type": "application/json",
|
|
299
|
-
...getHeaders(headers)
|
|
372
|
+
...await getHeaders(headers)
|
|
300
373
|
},
|
|
301
374
|
body: JSON.stringify({ storageUri })
|
|
302
375
|
});
|
|
@@ -319,7 +392,7 @@ const standaloneStorage = (config) => {
|
|
|
319
392
|
formData.append("key", key);
|
|
320
393
|
const response = await fetch(`${config.baseUrl}${path}`, {
|
|
321
394
|
method: "POST",
|
|
322
|
-
headers: getHeaders(headers),
|
|
395
|
+
headers: await getHeaders(headers),
|
|
323
396
|
body: formData
|
|
324
397
|
});
|
|
325
398
|
if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
|
|
@@ -340,6 +413,39 @@ const standaloneStorage = (config) => {
|
|
|
340
413
|
async delete({ storageUri }) {
|
|
341
414
|
await requestStorageUri("delete", storageUri);
|
|
342
415
|
return { deleted: true };
|
|
416
|
+
},
|
|
417
|
+
async listObjects(prefix) {
|
|
418
|
+
const { path, headers } = resolveRoute("listObjects", [{ prefix }]);
|
|
419
|
+
const objects = [];
|
|
420
|
+
let cursor;
|
|
421
|
+
do {
|
|
422
|
+
const response = await postJson(path, headers, {
|
|
423
|
+
prefix,
|
|
424
|
+
cursor
|
|
425
|
+
});
|
|
426
|
+
if (response.status === 404) throw new Error(`The storage service has no ${path} route, which storage prune needs.`);
|
|
427
|
+
if (!response.ok) throw new Error(`Failed to list storage objects: ${response.statusText}`);
|
|
428
|
+
const page = await response.json();
|
|
429
|
+
for (const object of page.objects) {
|
|
430
|
+
(0, _hot_updater_plugin_core.parseStorageUri)(object.storageUri, config.protocol);
|
|
431
|
+
objects.push({
|
|
432
|
+
key: object.key,
|
|
433
|
+
storageUri: object.storageUri,
|
|
434
|
+
size: object.size,
|
|
435
|
+
...object.lastModifiedAt === void 0 ? {} : { lastModifiedAt: new Date(object.lastModifiedAt) }
|
|
436
|
+
});
|
|
437
|
+
}
|
|
438
|
+
cursor = page.cursor;
|
|
439
|
+
} while (cursor !== void 0);
|
|
440
|
+
return objects;
|
|
441
|
+
},
|
|
442
|
+
async deleteObjects(keys) {
|
|
443
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
|
|
444
|
+
const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
|
|
445
|
+
const { path, headers } = resolveRoute("deleteObjects", [{ keys: batch }]);
|
|
446
|
+
const response = await postJson(path, headers, { keys: batch });
|
|
447
|
+
if (!response.ok) throw new Error(`Failed to delete storage objects: ${response.statusText}`);
|
|
448
|
+
}
|
|
343
449
|
}
|
|
344
450
|
});
|
|
345
451
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { HotUpdaterCoreApi, RemoteDatabase, StorageDeleteInput, StorageExistsInput, StorageGetInput, StoragePutInput } from "@hot-updater/plugin-core";
|
|
1
|
+
import { HotUpdaterCoreApi, Lazy, RemoteDatabase, StorageDeleteInput, StorageExistsInput, StorageGetInput, StorageObject, StoragePutInput } from "@hot-updater/plugin-core";
|
|
2
2
|
//#region src/standaloneRoutes.d.ts
|
|
3
3
|
interface StandaloneRepositoryConfig {
|
|
4
4
|
/** Base URL of the Hot Updater admin handler. */
|
|
5
5
|
readonly baseUrl: string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Headers sent with every admin request, such as its authorization. A
|
|
8
|
+
* value may be a function that returns it, such as `secret("<name>")` in
|
|
9
|
+
* `hot-updater.config.ts`, called on the first request.
|
|
10
|
+
*/
|
|
11
|
+
readonly commonHeaders?: Readonly<Record<string, Lazy<string>>>;
|
|
8
12
|
}
|
|
9
13
|
//#endregion
|
|
10
14
|
//#region src/standaloneCore.d.ts
|
|
@@ -48,12 +52,25 @@ interface StorageRoutes {
|
|
|
48
52
|
get: (input: StorageGetInput) => RouteConfig;
|
|
49
53
|
exists: (input: StorageExistsInput) => RouteConfig;
|
|
50
54
|
delete: (input: StorageDeleteInput) => RouteConfig;
|
|
55
|
+
/** Lists objects for `hot-updater storage prune`. */
|
|
56
|
+
listObjects: (input: {
|
|
57
|
+
readonly prefix?: string;
|
|
58
|
+
}) => RouteConfig;
|
|
59
|
+
/** Deletes exact keys for `hot-updater storage prune --yes`. */
|
|
60
|
+
deleteObjects: (input: {
|
|
61
|
+
readonly keys: readonly string[];
|
|
62
|
+
}) => RouteConfig;
|
|
51
63
|
}
|
|
52
64
|
interface StandaloneStorageConfig {
|
|
53
65
|
baseUrl: string;
|
|
54
66
|
/** Storage URI protocol owned by the remote implementation. */
|
|
55
67
|
protocol: string;
|
|
56
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Headers sent with every request. A value may be a function that returns
|
|
70
|
+
* it, such as `secret("<name>")` in `hot-updater.config.ts`, called on
|
|
71
|
+
* the first request.
|
|
72
|
+
*/
|
|
73
|
+
commonHeaders?: Record<string, Lazy<string>>;
|
|
57
74
|
routes?: Partial<StorageRoutes>;
|
|
58
75
|
}
|
|
59
76
|
declare const standaloneStorage: (config: StandaloneStorageConfig) => {
|
|
@@ -71,6 +88,8 @@ declare const standaloneStorage: (config: StandaloneStorageConfig) => {
|
|
|
71
88
|
readonly delete: ({ storageUri }: StorageDeleteInput) => Promise<{
|
|
72
89
|
deleted: true;
|
|
73
90
|
}>;
|
|
91
|
+
readonly listObjects: (prefix?: string) => Promise<StorageObject[]>;
|
|
92
|
+
readonly deleteObjects: (keys: readonly string[]) => Promise<void>;
|
|
74
93
|
};
|
|
75
94
|
//#endregion
|
|
76
95
|
export { RouteConfig, STANDALONE_ADMIN_PROTOCOL, StandaloneDatabaseError, StandaloneRepository, type StandaloneRepositoryConfig, StandaloneStorageConfig, StorageRoutes, createStandaloneCoreApi, standaloneRepository, standaloneStorage };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { HotUpdaterCoreApi, RemoteDatabase, StorageDeleteInput, StorageExistsInput, StorageGetInput, StoragePutInput } from "@hot-updater/plugin-core";
|
|
1
|
+
import { HotUpdaterCoreApi, Lazy, RemoteDatabase, StorageDeleteInput, StorageExistsInput, StorageGetInput, StorageObject, StoragePutInput } from "@hot-updater/plugin-core";
|
|
2
2
|
//#region src/standaloneRoutes.d.ts
|
|
3
3
|
interface StandaloneRepositoryConfig {
|
|
4
4
|
/** Base URL of the Hot Updater admin handler. */
|
|
5
5
|
readonly baseUrl: string;
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Headers sent with every admin request, such as its authorization. A
|
|
8
|
+
* value may be a function that returns it, such as `secret("<name>")` in
|
|
9
|
+
* `hot-updater.config.ts`, called on the first request.
|
|
10
|
+
*/
|
|
11
|
+
readonly commonHeaders?: Readonly<Record<string, Lazy<string>>>;
|
|
8
12
|
}
|
|
9
13
|
//#endregion
|
|
10
14
|
//#region src/standaloneCore.d.ts
|
|
@@ -48,12 +52,25 @@ interface StorageRoutes {
|
|
|
48
52
|
get: (input: StorageGetInput) => RouteConfig;
|
|
49
53
|
exists: (input: StorageExistsInput) => RouteConfig;
|
|
50
54
|
delete: (input: StorageDeleteInput) => RouteConfig;
|
|
55
|
+
/** Lists objects for `hot-updater storage prune`. */
|
|
56
|
+
listObjects: (input: {
|
|
57
|
+
readonly prefix?: string;
|
|
58
|
+
}) => RouteConfig;
|
|
59
|
+
/** Deletes exact keys for `hot-updater storage prune --yes`. */
|
|
60
|
+
deleteObjects: (input: {
|
|
61
|
+
readonly keys: readonly string[];
|
|
62
|
+
}) => RouteConfig;
|
|
51
63
|
}
|
|
52
64
|
interface StandaloneStorageConfig {
|
|
53
65
|
baseUrl: string;
|
|
54
66
|
/** Storage URI protocol owned by the remote implementation. */
|
|
55
67
|
protocol: string;
|
|
56
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Headers sent with every request. A value may be a function that returns
|
|
70
|
+
* it, such as `secret("<name>")` in `hot-updater.config.ts`, called on
|
|
71
|
+
* the first request.
|
|
72
|
+
*/
|
|
73
|
+
commonHeaders?: Record<string, Lazy<string>>;
|
|
57
74
|
routes?: Partial<StorageRoutes>;
|
|
58
75
|
}
|
|
59
76
|
declare const standaloneStorage: (config: StandaloneStorageConfig) => {
|
|
@@ -71,6 +88,8 @@ declare const standaloneStorage: (config: StandaloneStorageConfig) => {
|
|
|
71
88
|
readonly delete: ({ storageUri }: StorageDeleteInput) => Promise<{
|
|
72
89
|
deleted: true;
|
|
73
90
|
}>;
|
|
91
|
+
readonly listObjects: (prefix?: string) => Promise<StorageObject[]>;
|
|
92
|
+
readonly deleteObjects: (keys: readonly string[]) => Promise<void>;
|
|
74
93
|
};
|
|
75
94
|
//#endregion
|
|
76
95
|
export { RouteConfig, STANDALONE_ADMIN_PROTOCOL, StandaloneDatabaseError, StandaloneRepository, type StandaloneRepositoryConfig, StandaloneStorageConfig, StorageRoutes, createStandaloneCoreApi, standaloneRepository, standaloneStorage };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DatabaseBundleNotFoundError, ReleaseCatalogMutationError, ReleaseManagementError, createStorageAdapter, parseStorageUri } from "@hot-updater/plugin-core";
|
|
1
|
+
import { DatabaseBundleNotFoundError, ReleaseCatalogMutationError, ReleaseManagementError, createStorageAdapter, parseStorageUri, resolveLazy } from "@hot-updater/plugin-core";
|
|
2
2
|
//#region src/standaloneHttp.ts
|
|
3
3
|
var StandaloneDatabaseError = class extends Error {
|
|
4
4
|
code;
|
|
@@ -11,11 +11,13 @@ var StandaloneDatabaseError = class extends Error {
|
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
13
|
const isRecord$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
14
|
+
/** `headers` with each lazy value resolved. */
|
|
15
|
+
const resolveHeaders = async (headers = {}) => Object.fromEntries(await Promise.all(Object.entries(headers).map(async ([name, value]) => [name, await resolveLazy(value)])));
|
|
14
16
|
const createStandaloneHttp = (config) => {
|
|
15
17
|
const buildUrl = (path) => `${config.baseUrl.replace(/\/+$/, "")}${path}`;
|
|
16
|
-
const headers = (routeHeaders) => ({
|
|
18
|
+
const headers = async (routeHeaders) => ({
|
|
17
19
|
"Content-Type": "application/json",
|
|
18
|
-
...config.commonHeaders,
|
|
20
|
+
...await resolveHeaders(config.commonHeaders),
|
|
19
21
|
...routeHeaders
|
|
20
22
|
});
|
|
21
23
|
const requestFailed = async (response) => {
|
|
@@ -73,15 +75,22 @@ const refusal = (status, value, fallback) => {
|
|
|
73
75
|
}
|
|
74
76
|
return new StandaloneDatabaseError("request-failed", message, status);
|
|
75
77
|
};
|
|
76
|
-
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion }) => ({
|
|
78
|
+
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion, sandbox }) => ({
|
|
77
79
|
platform,
|
|
78
80
|
channel,
|
|
79
|
-
...fingerprintHash === null ? { appVersion } : { fingerprintHash }
|
|
81
|
+
...fingerprintHash === null ? { appVersion } : { fingerprintHash },
|
|
82
|
+
...sandbox === void 0 || sandbox === null ? {} : {
|
|
83
|
+
sandboxAppId: sandbox.appId,
|
|
84
|
+
sandboxUrlScheme: sandbox.urlScheme,
|
|
85
|
+
artifactKind: sandbox.artifactKind,
|
|
86
|
+
distribution: sandbox.distribution
|
|
87
|
+
}
|
|
80
88
|
});
|
|
81
|
-
const keysetParams = ({ order, after, limit }) => ({
|
|
89
|
+
const keysetParams = ({ order, after, through, limit }) => ({
|
|
82
90
|
limit: String(limit),
|
|
83
91
|
...order === void 0 ? {} : { order },
|
|
84
|
-
...after === void 0 ? {} : { cursor: after }
|
|
92
|
+
...after === void 0 ? {} : { cursor: after },
|
|
93
|
+
...through === void 0 ? {} : { through }
|
|
85
94
|
});
|
|
86
95
|
const filterParams = (filter) => {
|
|
87
96
|
switch (filter.kind) {
|
|
@@ -107,7 +116,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
107
116
|
const http = createStandaloneHttp(config);
|
|
108
117
|
let checked;
|
|
109
118
|
const checkProtocol = async () => {
|
|
110
|
-
const response = await fetch(http.buildUrl("/version"), { headers: http.headers({ "Cache-Control": "no-cache" }) });
|
|
119
|
+
const response = await fetch(http.buildUrl("/version"), { headers: await http.headers({ "Cache-Control": "no-cache" }) });
|
|
111
120
|
const body = response.status === 404 ? {} : await http.parseJson(response);
|
|
112
121
|
const protocol = isRecord(body) ? body.adminProtocol : void 0;
|
|
113
122
|
if (typeof protocol !== "number" || protocol < 2) throw new StandaloneDatabaseError("request-failed", `The server at ${config.baseUrl} does not report Hot Updater admin API protocol 2 at /version. Set baseUrl to the path where the server mounts handlers.admin, such as https://example.com/hot-updater/admin.`, response.status);
|
|
@@ -124,7 +133,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
124
133
|
for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
|
|
125
134
|
const response = await fetch(url, {
|
|
126
135
|
method,
|
|
127
|
-
headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
136
|
+
headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
128
137
|
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
129
138
|
});
|
|
130
139
|
if (response.status === 204) return null;
|
|
@@ -187,11 +196,17 @@ const createStandaloneCoreApi = (config) => {
|
|
|
187
196
|
const row = await call("GET", "/native-builds/latest", {
|
|
188
197
|
query: {
|
|
189
198
|
...nativeBuildScopeParams(scope),
|
|
190
|
-
...buildKey === void 0 ? {} : { buildKey }
|
|
199
|
+
...buildKey === void 0 ? {} : { buildKey },
|
|
200
|
+
...options?.storeBuild ? { storeBuild: "true" } : {},
|
|
201
|
+
...options?.builtInOlderThan === void 0 ? {} : { builtInOlderThan: options.builtInOlderThan }
|
|
191
202
|
},
|
|
192
203
|
requiredRoute: "native build"
|
|
193
204
|
});
|
|
194
|
-
|
|
205
|
+
if (buildKey !== void 0 && row?.build_key !== buildKey) return null;
|
|
206
|
+
if (options?.storeBuild && row?.is_store_build !== true) return null;
|
|
207
|
+
const sandbox = scope.sandbox;
|
|
208
|
+
if (sandbox && row !== null && (row.is_sandbox !== true || row.artifact_kind !== sandbox.artifactKind || row.sandbox_url_scheme !== sandbox.urlScheme)) return null;
|
|
209
|
+
return row;
|
|
195
210
|
},
|
|
196
211
|
listNativeBuilds: ({ channelId, ...input }) => list("/native-builds", {
|
|
197
212
|
...keysetParams(input),
|
|
@@ -235,6 +250,52 @@ const createStandaloneCoreApi = (config) => {
|
|
|
235
250
|
body: submission,
|
|
236
251
|
requiredRoute: "native build submission"
|
|
237
252
|
}),
|
|
253
|
+
markNativeBuild: (id, mark) => call("POST", `/native-builds/${encode(id)}/store-build`, {
|
|
254
|
+
body: mark,
|
|
255
|
+
requiredRoute: "native build store mark"
|
|
256
|
+
}),
|
|
257
|
+
listIosDevices: async ({ status, ...input }) => await call("GET", "/ios-devices", {
|
|
258
|
+
query: {
|
|
259
|
+
...keysetParams(input),
|
|
260
|
+
...status === void 0 ? {} : { status }
|
|
261
|
+
},
|
|
262
|
+
requiredRoute: "iOS device registry"
|
|
263
|
+
}) ?? [],
|
|
264
|
+
findIosDevice: (udid) => call("GET", `/ios-devices/udid/${encode(udid)}`, { requiredRoute: "iOS device registry" }),
|
|
265
|
+
requestIosDevice: async (input) => await call("POST", "/ios-devices", {
|
|
266
|
+
body: input,
|
|
267
|
+
requiredRoute: "iOS device registry"
|
|
268
|
+
}),
|
|
269
|
+
approveIosDevice: (id, input) => call("POST", `/ios-devices/${encode(id)}/approval`, {
|
|
270
|
+
body: input,
|
|
271
|
+
requiredRoute: "iOS device registry"
|
|
272
|
+
}),
|
|
273
|
+
renameIosDevice: (id, name) => call("PATCH", `/ios-devices/${encode(id)}`, {
|
|
274
|
+
body: { name },
|
|
275
|
+
requiredRoute: "iOS device registry"
|
|
276
|
+
}),
|
|
277
|
+
recordIosDeviceOutcome: ({ id, ...input }) => call("POST", `/ios-devices/${encode(id)}/outcome`, {
|
|
278
|
+
body: input,
|
|
279
|
+
requiredRoute: "iOS device registry"
|
|
280
|
+
}),
|
|
281
|
+
markIosDevicesInBuild: async (input) => {
|
|
282
|
+
await request("POST", "/ios-devices/in-build", {
|
|
283
|
+
body: input,
|
|
284
|
+
requiredRoute: "iOS device registry"
|
|
285
|
+
});
|
|
286
|
+
},
|
|
287
|
+
findIosDeviceAccount: () => call("GET", "/ios-devices/account", { requiredRoute: "iOS device registry" }),
|
|
288
|
+
claimIosDeviceAccount: async (issuerId) => await call("POST", "/ios-devices/account", {
|
|
289
|
+
body: { issuerId },
|
|
290
|
+
requiredRoute: "iOS device registry"
|
|
291
|
+
}),
|
|
292
|
+
deleteIosDevice: (id, only) => call("DELETE", `/ios-devices/${encode(id)}`, {
|
|
293
|
+
query: {
|
|
294
|
+
...only?.status === void 0 ? {} : { status: only.status },
|
|
295
|
+
...only?.requestedBy === void 0 ? {} : { requestedBy: only.requestedBy }
|
|
296
|
+
},
|
|
297
|
+
requiredRoute: "iOS device registry"
|
|
298
|
+
}),
|
|
238
299
|
deleteNativeBuild: async (id) => await call("DELETE", `/native-builds/${encode(id)}`, { requiredRoute: "native build deletion" })
|
|
239
300
|
};
|
|
240
301
|
};
|
|
@@ -251,8 +312,8 @@ const standaloneRepository = (config) => {
|
|
|
251
312
|
return Object.freeze({
|
|
252
313
|
name: "standalone-repository",
|
|
253
314
|
core: createStandaloneCoreApi(config),
|
|
254
|
-
fetchAdmin: (path, init = {}) => {
|
|
255
|
-
const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
|
|
315
|
+
fetchAdmin: async (path, init = {}) => {
|
|
316
|
+
const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
|
|
256
317
|
new Headers(init.headers).forEach((value, name) => {
|
|
257
318
|
headers.set(name, value);
|
|
258
319
|
});
|
|
@@ -269,8 +330,12 @@ const defaultRoutes = {
|
|
|
269
330
|
put: () => ({ path: "/upload" }),
|
|
270
331
|
get: () => ({ path: "/get" }),
|
|
271
332
|
exists: () => ({ path: "/exists" }),
|
|
272
|
-
delete: () => ({ path: "/delete" })
|
|
333
|
+
delete: () => ({ path: "/delete" }),
|
|
334
|
+
listObjects: () => ({ path: "/list" }),
|
|
335
|
+
deleteObjects: () => ({ path: "/delete-objects" })
|
|
273
336
|
};
|
|
337
|
+
/** Keys sent in one `deleteObjects` request. */
|
|
338
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
274
339
|
const createRoute = (defaultRoute, customRoute) => ({
|
|
275
340
|
path: customRoute?.path ?? defaultRoute.path,
|
|
276
341
|
headers: {
|
|
@@ -279,8 +344,8 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
279
344
|
}
|
|
280
345
|
});
|
|
281
346
|
const standaloneStorage = (config) => {
|
|
282
|
-
const getHeaders = (routeHeaders) => ({
|
|
283
|
-
...config.commonHeaders,
|
|
347
|
+
const getHeaders = async (routeHeaders) => ({
|
|
348
|
+
...await resolveHeaders(config.commonHeaders),
|
|
284
349
|
...routeHeaders
|
|
285
350
|
});
|
|
286
351
|
const resolveRoute = (name, args) => {
|
|
@@ -288,6 +353,14 @@ const standaloneStorage = (config) => {
|
|
|
288
353
|
const custom = config.routes?.[name];
|
|
289
354
|
return createRoute(fallback(...args), custom?.(...args));
|
|
290
355
|
};
|
|
356
|
+
const postJson = async (path, headers, body) => fetch(`${config.baseUrl}${path}`, {
|
|
357
|
+
method: "POST",
|
|
358
|
+
headers: {
|
|
359
|
+
"content-type": "application/json",
|
|
360
|
+
...await getHeaders(headers)
|
|
361
|
+
},
|
|
362
|
+
body: JSON.stringify(body)
|
|
363
|
+
});
|
|
291
364
|
const requestStorageUri = async (routeName, storageUri) => {
|
|
292
365
|
parseStorageUri(storageUri, config.protocol);
|
|
293
366
|
const { path, headers } = resolveRoute(routeName, [{ storageUri }]);
|
|
@@ -295,7 +368,7 @@ const standaloneStorage = (config) => {
|
|
|
295
368
|
method: routeName === "delete" ? "DELETE" : "POST",
|
|
296
369
|
headers: {
|
|
297
370
|
"content-type": "application/json",
|
|
298
|
-
...getHeaders(headers)
|
|
371
|
+
...await getHeaders(headers)
|
|
299
372
|
},
|
|
300
373
|
body: JSON.stringify({ storageUri })
|
|
301
374
|
});
|
|
@@ -318,7 +391,7 @@ const standaloneStorage = (config) => {
|
|
|
318
391
|
formData.append("key", key);
|
|
319
392
|
const response = await fetch(`${config.baseUrl}${path}`, {
|
|
320
393
|
method: "POST",
|
|
321
|
-
headers: getHeaders(headers),
|
|
394
|
+
headers: await getHeaders(headers),
|
|
322
395
|
body: formData
|
|
323
396
|
});
|
|
324
397
|
if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
|
|
@@ -339,6 +412,39 @@ const standaloneStorage = (config) => {
|
|
|
339
412
|
async delete({ storageUri }) {
|
|
340
413
|
await requestStorageUri("delete", storageUri);
|
|
341
414
|
return { deleted: true };
|
|
415
|
+
},
|
|
416
|
+
async listObjects(prefix) {
|
|
417
|
+
const { path, headers } = resolveRoute("listObjects", [{ prefix }]);
|
|
418
|
+
const objects = [];
|
|
419
|
+
let cursor;
|
|
420
|
+
do {
|
|
421
|
+
const response = await postJson(path, headers, {
|
|
422
|
+
prefix,
|
|
423
|
+
cursor
|
|
424
|
+
});
|
|
425
|
+
if (response.status === 404) throw new Error(`The storage service has no ${path} route, which storage prune needs.`);
|
|
426
|
+
if (!response.ok) throw new Error(`Failed to list storage objects: ${response.statusText}`);
|
|
427
|
+
const page = await response.json();
|
|
428
|
+
for (const object of page.objects) {
|
|
429
|
+
parseStorageUri(object.storageUri, config.protocol);
|
|
430
|
+
objects.push({
|
|
431
|
+
key: object.key,
|
|
432
|
+
storageUri: object.storageUri,
|
|
433
|
+
size: object.size,
|
|
434
|
+
...object.lastModifiedAt === void 0 ? {} : { lastModifiedAt: new Date(object.lastModifiedAt) }
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
cursor = page.cursor;
|
|
438
|
+
} while (cursor !== void 0);
|
|
439
|
+
return objects;
|
|
440
|
+
},
|
|
441
|
+
async deleteObjects(keys) {
|
|
442
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
|
|
443
|
+
const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
|
|
444
|
+
const { path, headers } = resolveRoute("deleteObjects", [{ keys: batch }]);
|
|
445
|
+
const response = await postJson(path, headers, { keys: batch });
|
|
446
|
+
if (!response.ok) throw new Error(`Failed to delete storage objects: ${response.statusText}`);
|
|
447
|
+
}
|
|
342
448
|
}
|
|
343
449
|
});
|
|
344
450
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/standalone",
|
|
3
|
-
"version": "1.2.0-rc.
|
|
3
|
+
"version": "1.2.0-rc.41",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"access": "public"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@hot-updater/protocol": "1.2.0-rc.
|
|
46
|
-
"@hot-updater/plugin-core": "1.2.0-rc.
|
|
45
|
+
"@hot-updater/protocol": "1.2.0-rc.41",
|
|
46
|
+
"@hot-updater/plugin-core": "1.2.0-rc.41"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"mime": "2.6.0",
|
|
@@ -52,12 +52,7 @@
|
|
|
52
52
|
"msw": "^2.7.0",
|
|
53
53
|
"verkit": "0.4.0",
|
|
54
54
|
"vitest": "4.1.4",
|
|
55
|
-
"@hot-updater/test-utils": "1.2.0-rc.
|
|
56
|
-
},
|
|
57
|
-
"nx": {
|
|
58
|
-
"implicitDependencies": [
|
|
59
|
-
"!@hot-updater/test-utils"
|
|
60
|
-
]
|
|
55
|
+
"@hot-updater/test-utils": "1.2.0-rc.41"
|
|
61
56
|
},
|
|
62
57
|
"scripts": {
|
|
63
58
|
"build": "tsdown",
|