@hot-updater/standalone 1.2.0-rc.5 → 1.2.0-rc.51
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 +177 -18
- package/dist/index.d.cts +23 -4
- package/dist/index.d.mts +23 -4
- package/dist/index.mjs +178 -19
- 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) => {
|
|
@@ -68,21 +70,31 @@ const refusal = (status, value, fallback) => {
|
|
|
68
70
|
const message = isRecord(value) && typeof value.error === "string" ? value.error : fallback;
|
|
69
71
|
if (typeof code === "string" && MANAGEMENT_CODES.has(code)) return new _hot_updater_plugin_core.ReleaseManagementError(code, message);
|
|
70
72
|
if (typeof code === "string" && CATALOG_CODES.has(code)) return new _hot_updater_plugin_core.ReleaseCatalogMutationError(code, message);
|
|
73
|
+
if (code === "CATALOG_OVERSIZE") return new _hot_updater_plugin_core.ReleaseCatalogCompilationError(code, message);
|
|
71
74
|
if (code === "BUNDLE_NOT_FOUND" && isRecord(value)) {
|
|
72
75
|
const id = /"([^"]+)"/u.exec(message)?.[1] ?? "";
|
|
73
76
|
return new _hot_updater_plugin_core.DatabaseBundleNotFoundError(id);
|
|
74
77
|
}
|
|
75
78
|
return new StandaloneDatabaseError("request-failed", message, status);
|
|
76
79
|
};
|
|
77
|
-
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion }) => ({
|
|
80
|
+
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion, sandbox }) => ({
|
|
78
81
|
platform,
|
|
79
82
|
channel,
|
|
80
|
-
...fingerprintHash === null ? { appVersion } : { fingerprintHash }
|
|
83
|
+
...fingerprintHash === null ? { appVersion } : { fingerprintHash },
|
|
84
|
+
...sandbox === void 0 || sandbox === null ? {} : {
|
|
85
|
+
sandboxAppId: sandbox.appId,
|
|
86
|
+
sandboxUrlScheme: sandbox.urlScheme,
|
|
87
|
+
artifactKind: sandbox.artifactKind,
|
|
88
|
+
distribution: sandbox.distribution
|
|
89
|
+
}
|
|
81
90
|
});
|
|
82
|
-
|
|
91
|
+
/** The most IDs the admin API takes in one request. */
|
|
92
|
+
const MAX_IDS = 100;
|
|
93
|
+
const keysetParams = ({ order, after, through, limit }) => ({
|
|
83
94
|
limit: String(limit),
|
|
84
95
|
...order === void 0 ? {} : { order },
|
|
85
|
-
...after === void 0 ? {} : { cursor: after }
|
|
96
|
+
...after === void 0 ? {} : { cursor: after },
|
|
97
|
+
...through === void 0 ? {} : { through }
|
|
86
98
|
});
|
|
87
99
|
const filterParams = (filter) => {
|
|
88
100
|
switch (filter.kind) {
|
|
@@ -108,7 +120,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
108
120
|
const http = createStandaloneHttp(config);
|
|
109
121
|
let checked;
|
|
110
122
|
const checkProtocol = async () => {
|
|
111
|
-
const response = await fetch(http.buildUrl("/version"), { headers: http.headers({ "Cache-Control": "no-cache" }) });
|
|
123
|
+
const response = await fetch(http.buildUrl("/version"), { headers: await http.headers({ "Cache-Control": "no-cache" }) });
|
|
112
124
|
const body = response.status === 404 ? {} : await http.parseJson(response);
|
|
113
125
|
const protocol = isRecord(body) ? body.adminProtocol : void 0;
|
|
114
126
|
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 +137,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
125
137
|
for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
|
|
126
138
|
const response = await fetch(url, {
|
|
127
139
|
method,
|
|
128
|
-
headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
140
|
+
headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
129
141
|
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
130
142
|
});
|
|
131
143
|
if (response.status === 204) return null;
|
|
@@ -174,26 +186,71 @@ const createStandaloneCoreApi = (config) => {
|
|
|
174
186
|
limit: String(limit)
|
|
175
187
|
}),
|
|
176
188
|
getRelease: (id) => call("GET", `/releases/${encode(id)}`),
|
|
189
|
+
getReleaseByLabel: ({ channel, platform, label }) => call("GET", "/release-labels", {
|
|
190
|
+
query: {
|
|
191
|
+
channel,
|
|
192
|
+
platform,
|
|
193
|
+
label: String(label)
|
|
194
|
+
},
|
|
195
|
+
requiredRoute: "release label"
|
|
196
|
+
}),
|
|
177
197
|
listReleases: ({ filter, ...input }) => list("/releases", {
|
|
178
198
|
...keysetParams(input),
|
|
179
199
|
...filterParams(filter)
|
|
180
200
|
}),
|
|
181
201
|
getReleaseCatalogRow: (scopeKey) => call("GET", `/release-catalogs/${encode(scopeKey)}`),
|
|
182
202
|
listReleaseCatalogs: (input) => list("/release-catalogs", keysetParams(input)),
|
|
183
|
-
|
|
203
|
+
listReleaseScopeKeys: async ({ after, limit }) => await call("GET", "/release-scopes", {
|
|
204
|
+
query: {
|
|
205
|
+
limit: String(limit),
|
|
206
|
+
...after === void 0 ? {} : { cursor: after }
|
|
207
|
+
},
|
|
208
|
+
requiredRoute: "release scope"
|
|
209
|
+
}) ?? [],
|
|
210
|
+
listChannels: async (input) => {
|
|
211
|
+
if (input === void 0) return list("/channels", {});
|
|
212
|
+
const rows = await list("/channels", keysetParams(input));
|
|
213
|
+
const desc = input.order === "desc";
|
|
214
|
+
const { after, through } = input;
|
|
215
|
+
const past = (name, bound) => desc ? (0, _hot_updater_plugin_core.compareUtf8)(name, bound) < 0 : (0, _hot_updater_plugin_core.compareUtf8)(name, bound) > 0;
|
|
216
|
+
return rows.filter(({ name }) => (after === void 0 || past(name, after)) && (through === void 0 || !past(name, through))).sort((left, right) => desc ? (0, _hot_updater_plugin_core.compareUtf8)(right.name, left.name) : (0, _hot_updater_plugin_core.compareUtf8)(left.name, right.name)).slice(0, input.limit);
|
|
217
|
+
},
|
|
218
|
+
getChannels: async (ids) => {
|
|
219
|
+
const unique = [...new Set(ids)];
|
|
220
|
+
const found = /* @__PURE__ */ new Map();
|
|
221
|
+
for (let start = 0; start < unique.length; start += MAX_IDS) {
|
|
222
|
+
const chunk = unique.slice(start, start + MAX_IDS);
|
|
223
|
+
const asked = new Set(chunk);
|
|
224
|
+
for (const row of await list("/channels", { ids: chunk.join(",") })) if (asked.has(row.id)) found.set(row.id, row);
|
|
225
|
+
}
|
|
226
|
+
return unique.flatMap((id) => {
|
|
227
|
+
const row = found.get(id);
|
|
228
|
+
return row === void 0 ? [] : [row];
|
|
229
|
+
});
|
|
230
|
+
},
|
|
184
231
|
findChannelByName: (name) => call("GET", "/channels", { query: { name } }),
|
|
185
232
|
getNativeBuild: (id) => call("GET", `/native-builds/${encode(id)}`, { requiredRoute: "native build" }),
|
|
233
|
+
findNativeBuildByBuiltInBundle: (bundleId) => call("GET", `/native-builds/built-in/${encode(bundleId)}`, { requiredRoute: "native build" }),
|
|
186
234
|
findNativeBuild: async (scope, options) => {
|
|
187
235
|
const buildKey = options?.buildKey;
|
|
188
236
|
const row = await call("GET", "/native-builds/latest", {
|
|
189
237
|
query: {
|
|
190
238
|
...nativeBuildScopeParams(scope),
|
|
191
|
-
...buildKey === void 0 ? {} : { buildKey }
|
|
239
|
+
...buildKey === void 0 ? {} : { buildKey },
|
|
240
|
+
...options?.storeBuild ? { storeBuild: "true" } : {},
|
|
241
|
+
...options?.builtInOlderThan === void 0 ? {} : { builtInOlderThan: options.builtInOlderThan },
|
|
242
|
+
...options?.artifactKind === void 0 ? {} : { kind: options.artifactKind }
|
|
192
243
|
},
|
|
193
244
|
requiredRoute: "native build"
|
|
194
245
|
});
|
|
195
|
-
|
|
246
|
+
if (buildKey !== void 0 && row?.build_key !== buildKey) return null;
|
|
247
|
+
if (options?.artifactKind !== void 0 && row !== null && row.artifact_kind !== options.artifactKind) return null;
|
|
248
|
+
if (options?.storeBuild && row?.is_store_build !== true) return null;
|
|
249
|
+
const sandbox = scope.sandbox;
|
|
250
|
+
if (sandbox && row !== null && (row.is_sandbox !== true || row.artifact_kind !== sandbox.artifactKind || row.sandbox_url_scheme !== sandbox.urlScheme)) return null;
|
|
251
|
+
return row;
|
|
196
252
|
},
|
|
253
|
+
findNativeBuildSibling: (build) => call("GET", `/native-builds/${encode(build.id)}/sibling`),
|
|
197
254
|
listNativeBuilds: ({ channelId, ...input }) => list("/native-builds", {
|
|
198
255
|
...keysetParams(input),
|
|
199
256
|
...channelId === void 0 ? {} : { channelId }
|
|
@@ -207,6 +264,10 @@ const createStandaloneCoreApi = (config) => {
|
|
|
207
264
|
} }),
|
|
208
265
|
promoteRelease: async ({ releaseId, ...input }) => await call("POST", `/releases/${encode(releaseId)}/promote`, { body: input }),
|
|
209
266
|
rebuildReleaseCatalog: async (scopeKey) => await call("POST", `/release-catalogs/${encode(scopeKey)}/rebuild`),
|
|
267
|
+
fillReleaseLabels: async (input = {}) => await call("POST", "/release-labels/fill", {
|
|
268
|
+
body: input,
|
|
269
|
+
requiredRoute: "release label"
|
|
270
|
+
}),
|
|
210
271
|
preflightReleaseCatalogRebuild: async (scopeKey) => await call("POST", `/release-catalogs/${encode(scopeKey)}/preflight`),
|
|
211
272
|
ensureChannel: async (name) => await call("POST", "/channels", { body: { name } }),
|
|
212
273
|
deleteChannel: async (id) => {
|
|
@@ -236,6 +297,59 @@ const createStandaloneCoreApi = (config) => {
|
|
|
236
297
|
body: submission,
|
|
237
298
|
requiredRoute: "native build submission"
|
|
238
299
|
}),
|
|
300
|
+
markNativeBuild: (id, mark) => call("POST", `/native-builds/${encode(id)}/store-build`, {
|
|
301
|
+
body: mark,
|
|
302
|
+
requiredRoute: "native build store mark"
|
|
303
|
+
}),
|
|
304
|
+
listIosDevices: async ({ status, ...input }) => await call("GET", "/ios-devices", {
|
|
305
|
+
query: {
|
|
306
|
+
...keysetParams(input),
|
|
307
|
+
...status === void 0 ? {} : { status }
|
|
308
|
+
},
|
|
309
|
+
requiredRoute: "iOS device registry"
|
|
310
|
+
}) ?? [],
|
|
311
|
+
findIosDevice: (udid) => call("GET", `/ios-devices/udid/${encode(udid)}`, { requiredRoute: "iOS device registry" }),
|
|
312
|
+
requestIosDevice: async (input) => await call("POST", "/ios-devices", {
|
|
313
|
+
body: input,
|
|
314
|
+
requiredRoute: "iOS device registry"
|
|
315
|
+
}),
|
|
316
|
+
approveIosDevice: (id, input) => call("POST", `/ios-devices/${encode(id)}/approval`, {
|
|
317
|
+
body: input,
|
|
318
|
+
requiredRoute: "iOS device registry"
|
|
319
|
+
}),
|
|
320
|
+
renameIosDevice: (id, name) => call("PATCH", `/ios-devices/${encode(id)}`, {
|
|
321
|
+
body: { name },
|
|
322
|
+
requiredRoute: "iOS device registry"
|
|
323
|
+
}),
|
|
324
|
+
recordIosDeviceOutcome: ({ id, ...input }) => call("POST", `/ios-devices/${encode(id)}/outcome`, {
|
|
325
|
+
body: input,
|
|
326
|
+
requiredRoute: "iOS device registry"
|
|
327
|
+
}),
|
|
328
|
+
markIosDevicesInBuild: async ({ buildId, ids }) => {
|
|
329
|
+
let start = 0;
|
|
330
|
+
do {
|
|
331
|
+
await request("POST", "/ios-devices/in-build", {
|
|
332
|
+
body: {
|
|
333
|
+
buildId,
|
|
334
|
+
ids: ids.slice(start, start + MAX_IDS)
|
|
335
|
+
},
|
|
336
|
+
requiredRoute: "iOS device registry"
|
|
337
|
+
});
|
|
338
|
+
start += MAX_IDS;
|
|
339
|
+
} while (start < ids.length);
|
|
340
|
+
},
|
|
341
|
+
findIosDeviceAccount: () => call("GET", "/ios-devices/account", { requiredRoute: "iOS device registry" }),
|
|
342
|
+
claimIosDeviceAccount: async (issuerId) => await call("POST", "/ios-devices/account", {
|
|
343
|
+
body: { issuerId },
|
|
344
|
+
requiredRoute: "iOS device registry"
|
|
345
|
+
}),
|
|
346
|
+
deleteIosDevice: (id, only) => call("DELETE", `/ios-devices/${encode(id)}`, {
|
|
347
|
+
query: {
|
|
348
|
+
...only?.status === void 0 ? {} : { status: only.status },
|
|
349
|
+
...only?.requestedBy === void 0 ? {} : { requestedBy: only.requestedBy }
|
|
350
|
+
},
|
|
351
|
+
requiredRoute: "iOS device registry"
|
|
352
|
+
}),
|
|
239
353
|
deleteNativeBuild: async (id) => await call("DELETE", `/native-builds/${encode(id)}`, { requiredRoute: "native build deletion" })
|
|
240
354
|
};
|
|
241
355
|
};
|
|
@@ -252,8 +366,8 @@ const standaloneRepository = (config) => {
|
|
|
252
366
|
return Object.freeze({
|
|
253
367
|
name: "standalone-repository",
|
|
254
368
|
core: createStandaloneCoreApi(config),
|
|
255
|
-
fetchAdmin: (path, init = {}) => {
|
|
256
|
-
const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
|
|
369
|
+
fetchAdmin: async (path, init = {}) => {
|
|
370
|
+
const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
|
|
257
371
|
new Headers(init.headers).forEach((value, name) => {
|
|
258
372
|
headers.set(name, value);
|
|
259
373
|
});
|
|
@@ -270,8 +384,12 @@ const defaultRoutes = {
|
|
|
270
384
|
put: () => ({ path: "/upload" }),
|
|
271
385
|
get: () => ({ path: "/get" }),
|
|
272
386
|
exists: () => ({ path: "/exists" }),
|
|
273
|
-
delete: () => ({ path: "/delete" })
|
|
387
|
+
delete: () => ({ path: "/delete" }),
|
|
388
|
+
listObjects: () => ({ path: "/list" }),
|
|
389
|
+
deleteObjects: () => ({ path: "/delete-objects" })
|
|
274
390
|
};
|
|
391
|
+
/** Keys sent in one `deleteObjects` request. */
|
|
392
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
275
393
|
const createRoute = (defaultRoute, customRoute) => ({
|
|
276
394
|
path: customRoute?.path ?? defaultRoute.path,
|
|
277
395
|
headers: {
|
|
@@ -280,8 +398,8 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
280
398
|
}
|
|
281
399
|
});
|
|
282
400
|
const standaloneStorage = (config) => {
|
|
283
|
-
const getHeaders = (routeHeaders) => ({
|
|
284
|
-
...config.commonHeaders,
|
|
401
|
+
const getHeaders = async (routeHeaders) => ({
|
|
402
|
+
...await resolveHeaders(config.commonHeaders),
|
|
285
403
|
...routeHeaders
|
|
286
404
|
});
|
|
287
405
|
const resolveRoute = (name, args) => {
|
|
@@ -289,6 +407,14 @@ const standaloneStorage = (config) => {
|
|
|
289
407
|
const custom = config.routes?.[name];
|
|
290
408
|
return createRoute(fallback(...args), custom?.(...args));
|
|
291
409
|
};
|
|
410
|
+
const postJson = async (path, headers, body) => fetch(`${config.baseUrl}${path}`, {
|
|
411
|
+
method: "POST",
|
|
412
|
+
headers: {
|
|
413
|
+
"content-type": "application/json",
|
|
414
|
+
...await getHeaders(headers)
|
|
415
|
+
},
|
|
416
|
+
body: JSON.stringify(body)
|
|
417
|
+
});
|
|
292
418
|
const requestStorageUri = async (routeName, storageUri) => {
|
|
293
419
|
(0, _hot_updater_plugin_core.parseStorageUri)(storageUri, config.protocol);
|
|
294
420
|
const { path, headers } = resolveRoute(routeName, [{ storageUri }]);
|
|
@@ -296,7 +422,7 @@ const standaloneStorage = (config) => {
|
|
|
296
422
|
method: routeName === "delete" ? "DELETE" : "POST",
|
|
297
423
|
headers: {
|
|
298
424
|
"content-type": "application/json",
|
|
299
|
-
...getHeaders(headers)
|
|
425
|
+
...await getHeaders(headers)
|
|
300
426
|
},
|
|
301
427
|
body: JSON.stringify({ storageUri })
|
|
302
428
|
});
|
|
@@ -319,7 +445,7 @@ const standaloneStorage = (config) => {
|
|
|
319
445
|
formData.append("key", key);
|
|
320
446
|
const response = await fetch(`${config.baseUrl}${path}`, {
|
|
321
447
|
method: "POST",
|
|
322
|
-
headers: getHeaders(headers),
|
|
448
|
+
headers: await getHeaders(headers),
|
|
323
449
|
body: formData
|
|
324
450
|
});
|
|
325
451
|
if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
|
|
@@ -340,6 +466,39 @@ const standaloneStorage = (config) => {
|
|
|
340
466
|
async delete({ storageUri }) {
|
|
341
467
|
await requestStorageUri("delete", storageUri);
|
|
342
468
|
return { deleted: true };
|
|
469
|
+
},
|
|
470
|
+
async listObjects(prefix) {
|
|
471
|
+
const { path, headers } = resolveRoute("listObjects", [{ prefix }]);
|
|
472
|
+
const objects = [];
|
|
473
|
+
let cursor;
|
|
474
|
+
do {
|
|
475
|
+
const response = await postJson(path, headers, {
|
|
476
|
+
prefix,
|
|
477
|
+
cursor
|
|
478
|
+
});
|
|
479
|
+
if (response.status === 404) throw new Error(`The storage service has no ${path} route, which storage prune needs.`);
|
|
480
|
+
if (!response.ok) throw new Error(`Failed to list storage objects: ${response.statusText}`);
|
|
481
|
+
const page = await response.json();
|
|
482
|
+
for (const object of page.objects) {
|
|
483
|
+
(0, _hot_updater_plugin_core.parseStorageUri)(object.storageUri, config.protocol);
|
|
484
|
+
objects.push({
|
|
485
|
+
key: object.key,
|
|
486
|
+
storageUri: object.storageUri,
|
|
487
|
+
size: object.size,
|
|
488
|
+
...object.lastModifiedAt === void 0 ? {} : { lastModifiedAt: new Date(object.lastModifiedAt) }
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
cursor = page.cursor;
|
|
492
|
+
} while (cursor !== void 0);
|
|
493
|
+
return objects;
|
|
494
|
+
},
|
|
495
|
+
async deleteObjects(keys) {
|
|
496
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
|
|
497
|
+
const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
|
|
498
|
+
const { path, headers } = resolveRoute("deleteObjects", [{ keys: batch }]);
|
|
499
|
+
const response = await postJson(path, headers, { keys: batch });
|
|
500
|
+
if (!response.ok) throw new Error(`Failed to delete storage objects: ${response.statusText}`);
|
|
501
|
+
}
|
|
343
502
|
}
|
|
344
503
|
});
|
|
345
504
|
};
|
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, ReleaseCatalogCompilationError, ReleaseCatalogMutationError, ReleaseManagementError, compareUtf8, 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) => {
|
|
@@ -67,21 +69,31 @@ const refusal = (status, value, fallback) => {
|
|
|
67
69
|
const message = isRecord(value) && typeof value.error === "string" ? value.error : fallback;
|
|
68
70
|
if (typeof code === "string" && MANAGEMENT_CODES.has(code)) return new ReleaseManagementError(code, message);
|
|
69
71
|
if (typeof code === "string" && CATALOG_CODES.has(code)) return new ReleaseCatalogMutationError(code, message);
|
|
72
|
+
if (code === "CATALOG_OVERSIZE") return new ReleaseCatalogCompilationError(code, message);
|
|
70
73
|
if (code === "BUNDLE_NOT_FOUND" && isRecord(value)) {
|
|
71
74
|
const id = /"([^"]+)"/u.exec(message)?.[1] ?? "";
|
|
72
75
|
return new DatabaseBundleNotFoundError(id);
|
|
73
76
|
}
|
|
74
77
|
return new StandaloneDatabaseError("request-failed", message, status);
|
|
75
78
|
};
|
|
76
|
-
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion }) => ({
|
|
79
|
+
const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion, sandbox }) => ({
|
|
77
80
|
platform,
|
|
78
81
|
channel,
|
|
79
|
-
...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
|
+
}
|
|
80
89
|
});
|
|
81
|
-
|
|
90
|
+
/** The most IDs the admin API takes in one request. */
|
|
91
|
+
const MAX_IDS = 100;
|
|
92
|
+
const keysetParams = ({ order, after, through, limit }) => ({
|
|
82
93
|
limit: String(limit),
|
|
83
94
|
...order === void 0 ? {} : { order },
|
|
84
|
-
...after === void 0 ? {} : { cursor: after }
|
|
95
|
+
...after === void 0 ? {} : { cursor: after },
|
|
96
|
+
...through === void 0 ? {} : { through }
|
|
85
97
|
});
|
|
86
98
|
const filterParams = (filter) => {
|
|
87
99
|
switch (filter.kind) {
|
|
@@ -107,7 +119,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
107
119
|
const http = createStandaloneHttp(config);
|
|
108
120
|
let checked;
|
|
109
121
|
const checkProtocol = async () => {
|
|
110
|
-
const response = await fetch(http.buildUrl("/version"), { headers: http.headers({ "Cache-Control": "no-cache" }) });
|
|
122
|
+
const response = await fetch(http.buildUrl("/version"), { headers: await http.headers({ "Cache-Control": "no-cache" }) });
|
|
111
123
|
const body = response.status === 404 ? {} : await http.parseJson(response);
|
|
112
124
|
const protocol = isRecord(body) ? body.adminProtocol : void 0;
|
|
113
125
|
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 +136,7 @@ const createStandaloneCoreApi = (config) => {
|
|
|
124
136
|
for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
|
|
125
137
|
const response = await fetch(url, {
|
|
126
138
|
method,
|
|
127
|
-
headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
139
|
+
headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
|
|
128
140
|
...body === void 0 ? {} : { body: JSON.stringify(body) }
|
|
129
141
|
});
|
|
130
142
|
if (response.status === 204) return null;
|
|
@@ -173,26 +185,71 @@ const createStandaloneCoreApi = (config) => {
|
|
|
173
185
|
limit: String(limit)
|
|
174
186
|
}),
|
|
175
187
|
getRelease: (id) => call("GET", `/releases/${encode(id)}`),
|
|
188
|
+
getReleaseByLabel: ({ channel, platform, label }) => call("GET", "/release-labels", {
|
|
189
|
+
query: {
|
|
190
|
+
channel,
|
|
191
|
+
platform,
|
|
192
|
+
label: String(label)
|
|
193
|
+
},
|
|
194
|
+
requiredRoute: "release label"
|
|
195
|
+
}),
|
|
176
196
|
listReleases: ({ filter, ...input }) => list("/releases", {
|
|
177
197
|
...keysetParams(input),
|
|
178
198
|
...filterParams(filter)
|
|
179
199
|
}),
|
|
180
200
|
getReleaseCatalogRow: (scopeKey) => call("GET", `/release-catalogs/${encode(scopeKey)}`),
|
|
181
201
|
listReleaseCatalogs: (input) => list("/release-catalogs", keysetParams(input)),
|
|
182
|
-
|
|
202
|
+
listReleaseScopeKeys: async ({ after, limit }) => await call("GET", "/release-scopes", {
|
|
203
|
+
query: {
|
|
204
|
+
limit: String(limit),
|
|
205
|
+
...after === void 0 ? {} : { cursor: after }
|
|
206
|
+
},
|
|
207
|
+
requiredRoute: "release scope"
|
|
208
|
+
}) ?? [],
|
|
209
|
+
listChannels: async (input) => {
|
|
210
|
+
if (input === void 0) return list("/channels", {});
|
|
211
|
+
const rows = await list("/channels", keysetParams(input));
|
|
212
|
+
const desc = input.order === "desc";
|
|
213
|
+
const { after, through } = input;
|
|
214
|
+
const past = (name, bound) => desc ? compareUtf8(name, bound) < 0 : compareUtf8(name, bound) > 0;
|
|
215
|
+
return rows.filter(({ name }) => (after === void 0 || past(name, after)) && (through === void 0 || !past(name, through))).sort((left, right) => desc ? compareUtf8(right.name, left.name) : compareUtf8(left.name, right.name)).slice(0, input.limit);
|
|
216
|
+
},
|
|
217
|
+
getChannels: async (ids) => {
|
|
218
|
+
const unique = [...new Set(ids)];
|
|
219
|
+
const found = /* @__PURE__ */ new Map();
|
|
220
|
+
for (let start = 0; start < unique.length; start += MAX_IDS) {
|
|
221
|
+
const chunk = unique.slice(start, start + MAX_IDS);
|
|
222
|
+
const asked = new Set(chunk);
|
|
223
|
+
for (const row of await list("/channels", { ids: chunk.join(",") })) if (asked.has(row.id)) found.set(row.id, row);
|
|
224
|
+
}
|
|
225
|
+
return unique.flatMap((id) => {
|
|
226
|
+
const row = found.get(id);
|
|
227
|
+
return row === void 0 ? [] : [row];
|
|
228
|
+
});
|
|
229
|
+
},
|
|
183
230
|
findChannelByName: (name) => call("GET", "/channels", { query: { name } }),
|
|
184
231
|
getNativeBuild: (id) => call("GET", `/native-builds/${encode(id)}`, { requiredRoute: "native build" }),
|
|
232
|
+
findNativeBuildByBuiltInBundle: (bundleId) => call("GET", `/native-builds/built-in/${encode(bundleId)}`, { requiredRoute: "native build" }),
|
|
185
233
|
findNativeBuild: async (scope, options) => {
|
|
186
234
|
const buildKey = options?.buildKey;
|
|
187
235
|
const row = await call("GET", "/native-builds/latest", {
|
|
188
236
|
query: {
|
|
189
237
|
...nativeBuildScopeParams(scope),
|
|
190
|
-
...buildKey === void 0 ? {} : { buildKey }
|
|
238
|
+
...buildKey === void 0 ? {} : { buildKey },
|
|
239
|
+
...options?.storeBuild ? { storeBuild: "true" } : {},
|
|
240
|
+
...options?.builtInOlderThan === void 0 ? {} : { builtInOlderThan: options.builtInOlderThan },
|
|
241
|
+
...options?.artifactKind === void 0 ? {} : { kind: options.artifactKind }
|
|
191
242
|
},
|
|
192
243
|
requiredRoute: "native build"
|
|
193
244
|
});
|
|
194
|
-
|
|
245
|
+
if (buildKey !== void 0 && row?.build_key !== buildKey) return null;
|
|
246
|
+
if (options?.artifactKind !== void 0 && row !== null && row.artifact_kind !== options.artifactKind) return null;
|
|
247
|
+
if (options?.storeBuild && row?.is_store_build !== true) return null;
|
|
248
|
+
const sandbox = scope.sandbox;
|
|
249
|
+
if (sandbox && row !== null && (row.is_sandbox !== true || row.artifact_kind !== sandbox.artifactKind || row.sandbox_url_scheme !== sandbox.urlScheme)) return null;
|
|
250
|
+
return row;
|
|
195
251
|
},
|
|
252
|
+
findNativeBuildSibling: (build) => call("GET", `/native-builds/${encode(build.id)}/sibling`),
|
|
196
253
|
listNativeBuilds: ({ channelId, ...input }) => list("/native-builds", {
|
|
197
254
|
...keysetParams(input),
|
|
198
255
|
...channelId === void 0 ? {} : { channelId }
|
|
@@ -206,6 +263,10 @@ const createStandaloneCoreApi = (config) => {
|
|
|
206
263
|
} }),
|
|
207
264
|
promoteRelease: async ({ releaseId, ...input }) => await call("POST", `/releases/${encode(releaseId)}/promote`, { body: input }),
|
|
208
265
|
rebuildReleaseCatalog: async (scopeKey) => await call("POST", `/release-catalogs/${encode(scopeKey)}/rebuild`),
|
|
266
|
+
fillReleaseLabels: async (input = {}) => await call("POST", "/release-labels/fill", {
|
|
267
|
+
body: input,
|
|
268
|
+
requiredRoute: "release label"
|
|
269
|
+
}),
|
|
209
270
|
preflightReleaseCatalogRebuild: async (scopeKey) => await call("POST", `/release-catalogs/${encode(scopeKey)}/preflight`),
|
|
210
271
|
ensureChannel: async (name) => await call("POST", "/channels", { body: { name } }),
|
|
211
272
|
deleteChannel: async (id) => {
|
|
@@ -235,6 +296,59 @@ const createStandaloneCoreApi = (config) => {
|
|
|
235
296
|
body: submission,
|
|
236
297
|
requiredRoute: "native build submission"
|
|
237
298
|
}),
|
|
299
|
+
markNativeBuild: (id, mark) => call("POST", `/native-builds/${encode(id)}/store-build`, {
|
|
300
|
+
body: mark,
|
|
301
|
+
requiredRoute: "native build store mark"
|
|
302
|
+
}),
|
|
303
|
+
listIosDevices: async ({ status, ...input }) => await call("GET", "/ios-devices", {
|
|
304
|
+
query: {
|
|
305
|
+
...keysetParams(input),
|
|
306
|
+
...status === void 0 ? {} : { status }
|
|
307
|
+
},
|
|
308
|
+
requiredRoute: "iOS device registry"
|
|
309
|
+
}) ?? [],
|
|
310
|
+
findIosDevice: (udid) => call("GET", `/ios-devices/udid/${encode(udid)}`, { requiredRoute: "iOS device registry" }),
|
|
311
|
+
requestIosDevice: async (input) => await call("POST", "/ios-devices", {
|
|
312
|
+
body: input,
|
|
313
|
+
requiredRoute: "iOS device registry"
|
|
314
|
+
}),
|
|
315
|
+
approveIosDevice: (id, input) => call("POST", `/ios-devices/${encode(id)}/approval`, {
|
|
316
|
+
body: input,
|
|
317
|
+
requiredRoute: "iOS device registry"
|
|
318
|
+
}),
|
|
319
|
+
renameIosDevice: (id, name) => call("PATCH", `/ios-devices/${encode(id)}`, {
|
|
320
|
+
body: { name },
|
|
321
|
+
requiredRoute: "iOS device registry"
|
|
322
|
+
}),
|
|
323
|
+
recordIosDeviceOutcome: ({ id, ...input }) => call("POST", `/ios-devices/${encode(id)}/outcome`, {
|
|
324
|
+
body: input,
|
|
325
|
+
requiredRoute: "iOS device registry"
|
|
326
|
+
}),
|
|
327
|
+
markIosDevicesInBuild: async ({ buildId, ids }) => {
|
|
328
|
+
let start = 0;
|
|
329
|
+
do {
|
|
330
|
+
await request("POST", "/ios-devices/in-build", {
|
|
331
|
+
body: {
|
|
332
|
+
buildId,
|
|
333
|
+
ids: ids.slice(start, start + MAX_IDS)
|
|
334
|
+
},
|
|
335
|
+
requiredRoute: "iOS device registry"
|
|
336
|
+
});
|
|
337
|
+
start += MAX_IDS;
|
|
338
|
+
} while (start < ids.length);
|
|
339
|
+
},
|
|
340
|
+
findIosDeviceAccount: () => call("GET", "/ios-devices/account", { requiredRoute: "iOS device registry" }),
|
|
341
|
+
claimIosDeviceAccount: async (issuerId) => await call("POST", "/ios-devices/account", {
|
|
342
|
+
body: { issuerId },
|
|
343
|
+
requiredRoute: "iOS device registry"
|
|
344
|
+
}),
|
|
345
|
+
deleteIosDevice: (id, only) => call("DELETE", `/ios-devices/${encode(id)}`, {
|
|
346
|
+
query: {
|
|
347
|
+
...only?.status === void 0 ? {} : { status: only.status },
|
|
348
|
+
...only?.requestedBy === void 0 ? {} : { requestedBy: only.requestedBy }
|
|
349
|
+
},
|
|
350
|
+
requiredRoute: "iOS device registry"
|
|
351
|
+
}),
|
|
238
352
|
deleteNativeBuild: async (id) => await call("DELETE", `/native-builds/${encode(id)}`, { requiredRoute: "native build deletion" })
|
|
239
353
|
};
|
|
240
354
|
};
|
|
@@ -251,8 +365,8 @@ const standaloneRepository = (config) => {
|
|
|
251
365
|
return Object.freeze({
|
|
252
366
|
name: "standalone-repository",
|
|
253
367
|
core: createStandaloneCoreApi(config),
|
|
254
|
-
fetchAdmin: (path, init = {}) => {
|
|
255
|
-
const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
|
|
368
|
+
fetchAdmin: async (path, init = {}) => {
|
|
369
|
+
const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
|
|
256
370
|
new Headers(init.headers).forEach((value, name) => {
|
|
257
371
|
headers.set(name, value);
|
|
258
372
|
});
|
|
@@ -269,8 +383,12 @@ const defaultRoutes = {
|
|
|
269
383
|
put: () => ({ path: "/upload" }),
|
|
270
384
|
get: () => ({ path: "/get" }),
|
|
271
385
|
exists: () => ({ path: "/exists" }),
|
|
272
|
-
delete: () => ({ path: "/delete" })
|
|
386
|
+
delete: () => ({ path: "/delete" }),
|
|
387
|
+
listObjects: () => ({ path: "/list" }),
|
|
388
|
+
deleteObjects: () => ({ path: "/delete-objects" })
|
|
273
389
|
};
|
|
390
|
+
/** Keys sent in one `deleteObjects` request. */
|
|
391
|
+
const DELETE_BATCH_SIZE = 1e3;
|
|
274
392
|
const createRoute = (defaultRoute, customRoute) => ({
|
|
275
393
|
path: customRoute?.path ?? defaultRoute.path,
|
|
276
394
|
headers: {
|
|
@@ -279,8 +397,8 @@ const createRoute = (defaultRoute, customRoute) => ({
|
|
|
279
397
|
}
|
|
280
398
|
});
|
|
281
399
|
const standaloneStorage = (config) => {
|
|
282
|
-
const getHeaders = (routeHeaders) => ({
|
|
283
|
-
...config.commonHeaders,
|
|
400
|
+
const getHeaders = async (routeHeaders) => ({
|
|
401
|
+
...await resolveHeaders(config.commonHeaders),
|
|
284
402
|
...routeHeaders
|
|
285
403
|
});
|
|
286
404
|
const resolveRoute = (name, args) => {
|
|
@@ -288,6 +406,14 @@ const standaloneStorage = (config) => {
|
|
|
288
406
|
const custom = config.routes?.[name];
|
|
289
407
|
return createRoute(fallback(...args), custom?.(...args));
|
|
290
408
|
};
|
|
409
|
+
const postJson = async (path, headers, body) => fetch(`${config.baseUrl}${path}`, {
|
|
410
|
+
method: "POST",
|
|
411
|
+
headers: {
|
|
412
|
+
"content-type": "application/json",
|
|
413
|
+
...await getHeaders(headers)
|
|
414
|
+
},
|
|
415
|
+
body: JSON.stringify(body)
|
|
416
|
+
});
|
|
291
417
|
const requestStorageUri = async (routeName, storageUri) => {
|
|
292
418
|
parseStorageUri(storageUri, config.protocol);
|
|
293
419
|
const { path, headers } = resolveRoute(routeName, [{ storageUri }]);
|
|
@@ -295,7 +421,7 @@ const standaloneStorage = (config) => {
|
|
|
295
421
|
method: routeName === "delete" ? "DELETE" : "POST",
|
|
296
422
|
headers: {
|
|
297
423
|
"content-type": "application/json",
|
|
298
|
-
...getHeaders(headers)
|
|
424
|
+
...await getHeaders(headers)
|
|
299
425
|
},
|
|
300
426
|
body: JSON.stringify({ storageUri })
|
|
301
427
|
});
|
|
@@ -318,7 +444,7 @@ const standaloneStorage = (config) => {
|
|
|
318
444
|
formData.append("key", key);
|
|
319
445
|
const response = await fetch(`${config.baseUrl}${path}`, {
|
|
320
446
|
method: "POST",
|
|
321
|
-
headers: getHeaders(headers),
|
|
447
|
+
headers: await getHeaders(headers),
|
|
322
448
|
body: formData
|
|
323
449
|
});
|
|
324
450
|
if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
|
|
@@ -339,6 +465,39 @@ const standaloneStorage = (config) => {
|
|
|
339
465
|
async delete({ storageUri }) {
|
|
340
466
|
await requestStorageUri("delete", storageUri);
|
|
341
467
|
return { deleted: true };
|
|
468
|
+
},
|
|
469
|
+
async listObjects(prefix) {
|
|
470
|
+
const { path, headers } = resolveRoute("listObjects", [{ prefix }]);
|
|
471
|
+
const objects = [];
|
|
472
|
+
let cursor;
|
|
473
|
+
do {
|
|
474
|
+
const response = await postJson(path, headers, {
|
|
475
|
+
prefix,
|
|
476
|
+
cursor
|
|
477
|
+
});
|
|
478
|
+
if (response.status === 404) throw new Error(`The storage service has no ${path} route, which storage prune needs.`);
|
|
479
|
+
if (!response.ok) throw new Error(`Failed to list storage objects: ${response.statusText}`);
|
|
480
|
+
const page = await response.json();
|
|
481
|
+
for (const object of page.objects) {
|
|
482
|
+
parseStorageUri(object.storageUri, config.protocol);
|
|
483
|
+
objects.push({
|
|
484
|
+
key: object.key,
|
|
485
|
+
storageUri: object.storageUri,
|
|
486
|
+
size: object.size,
|
|
487
|
+
...object.lastModifiedAt === void 0 ? {} : { lastModifiedAt: new Date(object.lastModifiedAt) }
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
cursor = page.cursor;
|
|
491
|
+
} while (cursor !== void 0);
|
|
492
|
+
return objects;
|
|
493
|
+
},
|
|
494
|
+
async deleteObjects(keys) {
|
|
495
|
+
for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
|
|
496
|
+
const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
|
|
497
|
+
const { path, headers } = resolveRoute("deleteObjects", [{ keys: batch }]);
|
|
498
|
+
const response = await postJson(path, headers, { keys: batch });
|
|
499
|
+
if (!response.ok) throw new Error(`Failed to delete storage objects: ${response.statusText}`);
|
|
500
|
+
}
|
|
342
501
|
}
|
|
343
502
|
});
|
|
344
503
|
};
|
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.51",
|
|
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.51",
|
|
46
|
+
"@hot-updater/plugin-core": "1.2.0-rc.51"
|
|
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.51"
|
|
61
56
|
},
|
|
62
57
|
"scripts": {
|
|
63
58
|
"build": "tsdown",
|