@hot-updater/standalone 1.2.0-rc.3 → 1.2.0-rc.31

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 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) => {
@@ -79,10 +81,11 @@ const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion
79
81
  channel,
80
82
  ...fingerprintHash === null ? { appVersion } : { fingerprintHash }
81
83
  });
82
- const keysetParams = ({ order, after, limit }) => ({
84
+ const keysetParams = ({ order, after, through, limit }) => ({
83
85
  limit: String(limit),
84
86
  ...order === void 0 ? {} : { order },
85
- ...after === void 0 ? {} : { cursor: after }
87
+ ...after === void 0 ? {} : { cursor: after },
88
+ ...through === void 0 ? {} : { through }
86
89
  });
87
90
  const filterParams = (filter) => {
88
91
  switch (filter.kind) {
@@ -108,7 +111,7 @@ const createStandaloneCoreApi = (config) => {
108
111
  const http = createStandaloneHttp(config);
109
112
  let checked;
110
113
  const checkProtocol = async () => {
111
- const response = await fetch(http.buildUrl("/version"), { headers: http.headers({ "Cache-Control": "no-cache" }) });
114
+ const response = await fetch(http.buildUrl("/version"), { headers: await http.headers({ "Cache-Control": "no-cache" }) });
112
115
  const body = response.status === 404 ? {} : await http.parseJson(response);
113
116
  const protocol = isRecord(body) ? body.adminProtocol : void 0;
114
117
  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 +128,7 @@ const createStandaloneCoreApi = (config) => {
125
128
  for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
126
129
  const response = await fetch(url, {
127
130
  method,
128
- headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
131
+ headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
129
132
  ...body === void 0 ? {} : { body: JSON.stringify(body) }
130
133
  });
131
134
  if (response.status === 204) return null;
@@ -188,11 +191,15 @@ const createStandaloneCoreApi = (config) => {
188
191
  const row = await call("GET", "/native-builds/latest", {
189
192
  query: {
190
193
  ...nativeBuildScopeParams(scope),
191
- ...buildKey === void 0 ? {} : { buildKey }
194
+ ...buildKey === void 0 ? {} : { buildKey },
195
+ ...options?.storeBuild ? { storeBuild: "true" } : {},
196
+ ...options?.builtInOlderThan === void 0 ? {} : { builtInOlderThan: options.builtInOlderThan }
192
197
  },
193
198
  requiredRoute: "native build"
194
199
  });
195
- return buildKey !== void 0 && row?.build_key !== buildKey ? null : row;
200
+ if (buildKey !== void 0 && row?.build_key !== buildKey) return null;
201
+ if (options?.storeBuild && row?.is_store_build !== true) return null;
202
+ return row;
196
203
  },
197
204
  listNativeBuilds: ({ channelId, ...input }) => list("/native-builds", {
198
205
  ...keysetParams(input),
@@ -236,6 +243,51 @@ const createStandaloneCoreApi = (config) => {
236
243
  body: submission,
237
244
  requiredRoute: "native build submission"
238
245
  }),
246
+ markNativeBuild: (id, mark) => call("POST", `/native-builds/${encode(id)}/store-build`, {
247
+ body: mark,
248
+ requiredRoute: "native build store mark"
249
+ }),
250
+ listIosDevices: async ({ status, ...input }) => await call("GET", "/ios-devices", {
251
+ query: {
252
+ ...keysetParams(input),
253
+ ...status === void 0 ? {} : { status }
254
+ },
255
+ requiredRoute: "iOS device registry"
256
+ }) ?? [],
257
+ findIosDevice: (udid) => call("GET", `/ios-devices/udid/${encode(udid)}`, { requiredRoute: "iOS device registry" }),
258
+ requestIosDevice: async (input) => await call("POST", "/ios-devices", {
259
+ body: input,
260
+ requiredRoute: "iOS device registry"
261
+ }),
262
+ approveIosDevice: (id, input) => call("POST", `/ios-devices/${encode(id)}/approval`, {
263
+ body: input,
264
+ requiredRoute: "iOS device registry"
265
+ }),
266
+ renameIosDevice: (id, name) => call("PATCH", `/ios-devices/${encode(id)}`, {
267
+ body: { name },
268
+ requiredRoute: "iOS device registry"
269
+ }),
270
+ recordIosDeviceOutcome: ({ id, ...input }) => call("POST", `/ios-devices/${encode(id)}/outcome`, {
271
+ body: input,
272
+ requiredRoute: "iOS device registry"
273
+ }),
274
+ markIosDevicesInBuild: async (input) => {
275
+ await request("POST", "/ios-devices/in-build", {
276
+ body: input,
277
+ requiredRoute: "iOS device registry"
278
+ });
279
+ },
280
+ claimIosDeviceAccount: async (issuerId) => await call("POST", "/ios-devices/account", {
281
+ body: { issuerId },
282
+ requiredRoute: "iOS device registry"
283
+ }),
284
+ deleteIosDevice: (id, only) => call("DELETE", `/ios-devices/${encode(id)}`, {
285
+ query: {
286
+ ...only?.status === void 0 ? {} : { status: only.status },
287
+ ...only?.requestedBy === void 0 ? {} : { requestedBy: only.requestedBy }
288
+ },
289
+ requiredRoute: "iOS device registry"
290
+ }),
239
291
  deleteNativeBuild: async (id) => await call("DELETE", `/native-builds/${encode(id)}`, { requiredRoute: "native build deletion" })
240
292
  };
241
293
  };
@@ -252,8 +304,8 @@ const standaloneRepository = (config) => {
252
304
  return Object.freeze({
253
305
  name: "standalone-repository",
254
306
  core: createStandaloneCoreApi(config),
255
- fetchAdmin: (path, init = {}) => {
256
- const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
307
+ fetchAdmin: async (path, init = {}) => {
308
+ const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
257
309
  new Headers(init.headers).forEach((value, name) => {
258
310
  headers.set(name, value);
259
311
  });
@@ -270,8 +322,12 @@ const defaultRoutes = {
270
322
  put: () => ({ path: "/upload" }),
271
323
  get: () => ({ path: "/get" }),
272
324
  exists: () => ({ path: "/exists" }),
273
- delete: () => ({ path: "/delete" })
325
+ delete: () => ({ path: "/delete" }),
326
+ listObjects: () => ({ path: "/list" }),
327
+ deleteObjects: () => ({ path: "/delete-objects" })
274
328
  };
329
+ /** Keys sent in one `deleteObjects` request. */
330
+ const DELETE_BATCH_SIZE = 1e3;
275
331
  const createRoute = (defaultRoute, customRoute) => ({
276
332
  path: customRoute?.path ?? defaultRoute.path,
277
333
  headers: {
@@ -280,8 +336,8 @@ const createRoute = (defaultRoute, customRoute) => ({
280
336
  }
281
337
  });
282
338
  const standaloneStorage = (config) => {
283
- const getHeaders = (routeHeaders) => ({
284
- ...config.commonHeaders,
339
+ const getHeaders = async (routeHeaders) => ({
340
+ ...await resolveHeaders(config.commonHeaders),
285
341
  ...routeHeaders
286
342
  });
287
343
  const resolveRoute = (name, args) => {
@@ -289,6 +345,14 @@ const standaloneStorage = (config) => {
289
345
  const custom = config.routes?.[name];
290
346
  return createRoute(fallback(...args), custom?.(...args));
291
347
  };
348
+ const postJson = async (path, headers, body) => fetch(`${config.baseUrl}${path}`, {
349
+ method: "POST",
350
+ headers: {
351
+ "content-type": "application/json",
352
+ ...await getHeaders(headers)
353
+ },
354
+ body: JSON.stringify(body)
355
+ });
292
356
  const requestStorageUri = async (routeName, storageUri) => {
293
357
  (0, _hot_updater_plugin_core.parseStorageUri)(storageUri, config.protocol);
294
358
  const { path, headers } = resolveRoute(routeName, [{ storageUri }]);
@@ -296,7 +360,7 @@ const standaloneStorage = (config) => {
296
360
  method: routeName === "delete" ? "DELETE" : "POST",
297
361
  headers: {
298
362
  "content-type": "application/json",
299
- ...getHeaders(headers)
363
+ ...await getHeaders(headers)
300
364
  },
301
365
  body: JSON.stringify({ storageUri })
302
366
  });
@@ -319,7 +383,7 @@ const standaloneStorage = (config) => {
319
383
  formData.append("key", key);
320
384
  const response = await fetch(`${config.baseUrl}${path}`, {
321
385
  method: "POST",
322
- headers: getHeaders(headers),
386
+ headers: await getHeaders(headers),
323
387
  body: formData
324
388
  });
325
389
  if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
@@ -340,6 +404,39 @@ const standaloneStorage = (config) => {
340
404
  async delete({ storageUri }) {
341
405
  await requestStorageUri("delete", storageUri);
342
406
  return { deleted: true };
407
+ },
408
+ async listObjects(prefix) {
409
+ const { path, headers } = resolveRoute("listObjects", [{ prefix }]);
410
+ const objects = [];
411
+ let cursor;
412
+ do {
413
+ const response = await postJson(path, headers, {
414
+ prefix,
415
+ cursor
416
+ });
417
+ if (response.status === 404) throw new Error(`The storage service has no ${path} route, which storage prune needs.`);
418
+ if (!response.ok) throw new Error(`Failed to list storage objects: ${response.statusText}`);
419
+ const page = await response.json();
420
+ for (const object of page.objects) {
421
+ (0, _hot_updater_plugin_core.parseStorageUri)(object.storageUri, config.protocol);
422
+ objects.push({
423
+ key: object.key,
424
+ storageUri: object.storageUri,
425
+ size: object.size,
426
+ ...object.lastModifiedAt === void 0 ? {} : { lastModifiedAt: new Date(object.lastModifiedAt) }
427
+ });
428
+ }
429
+ cursor = page.cursor;
430
+ } while (cursor !== void 0);
431
+ return objects;
432
+ },
433
+ async deleteObjects(keys) {
434
+ for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
435
+ const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
436
+ const { path, headers } = resolveRoute("deleteObjects", [{ keys: batch }]);
437
+ const response = await postJson(path, headers, { keys: batch });
438
+ if (!response.ok) throw new Error(`Failed to delete storage objects: ${response.statusText}`);
439
+ }
343
440
  }
344
441
  });
345
442
  };
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
- /** Headers sent with every admin request, such as its authorization. */
7
- readonly commonHeaders?: Readonly<Record<string, string>>;
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
- commonHeaders?: Record<string, string>;
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
- /** Headers sent with every admin request, such as its authorization. */
7
- readonly commonHeaders?: Readonly<Record<string, string>>;
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
- commonHeaders?: Record<string, string>;
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) => {
@@ -78,10 +80,11 @@ const nativeBuildScopeParams = ({ platform, channel, fingerprintHash, appVersion
78
80
  channel,
79
81
  ...fingerprintHash === null ? { appVersion } : { fingerprintHash }
80
82
  });
81
- const keysetParams = ({ order, after, limit }) => ({
83
+ const keysetParams = ({ order, after, through, limit }) => ({
82
84
  limit: String(limit),
83
85
  ...order === void 0 ? {} : { order },
84
- ...after === void 0 ? {} : { cursor: after }
86
+ ...after === void 0 ? {} : { cursor: after },
87
+ ...through === void 0 ? {} : { through }
85
88
  });
86
89
  const filterParams = (filter) => {
87
90
  switch (filter.kind) {
@@ -107,7 +110,7 @@ const createStandaloneCoreApi = (config) => {
107
110
  const http = createStandaloneHttp(config);
108
111
  let checked;
109
112
  const checkProtocol = async () => {
110
- const response = await fetch(http.buildUrl("/version"), { headers: http.headers({ "Cache-Control": "no-cache" }) });
113
+ const response = await fetch(http.buildUrl("/version"), { headers: await http.headers({ "Cache-Control": "no-cache" }) });
111
114
  const body = response.status === 404 ? {} : await http.parseJson(response);
112
115
  const protocol = isRecord(body) ? body.adminProtocol : void 0;
113
116
  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 +127,7 @@ const createStandaloneCoreApi = (config) => {
124
127
  for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
125
128
  const response = await fetch(url, {
126
129
  method,
127
- headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
130
+ headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
128
131
  ...body === void 0 ? {} : { body: JSON.stringify(body) }
129
132
  });
130
133
  if (response.status === 204) return null;
@@ -187,11 +190,15 @@ const createStandaloneCoreApi = (config) => {
187
190
  const row = await call("GET", "/native-builds/latest", {
188
191
  query: {
189
192
  ...nativeBuildScopeParams(scope),
190
- ...buildKey === void 0 ? {} : { buildKey }
193
+ ...buildKey === void 0 ? {} : { buildKey },
194
+ ...options?.storeBuild ? { storeBuild: "true" } : {},
195
+ ...options?.builtInOlderThan === void 0 ? {} : { builtInOlderThan: options.builtInOlderThan }
191
196
  },
192
197
  requiredRoute: "native build"
193
198
  });
194
- return buildKey !== void 0 && row?.build_key !== buildKey ? null : row;
199
+ if (buildKey !== void 0 && row?.build_key !== buildKey) return null;
200
+ if (options?.storeBuild && row?.is_store_build !== true) return null;
201
+ return row;
195
202
  },
196
203
  listNativeBuilds: ({ channelId, ...input }) => list("/native-builds", {
197
204
  ...keysetParams(input),
@@ -235,6 +242,51 @@ const createStandaloneCoreApi = (config) => {
235
242
  body: submission,
236
243
  requiredRoute: "native build submission"
237
244
  }),
245
+ markNativeBuild: (id, mark) => call("POST", `/native-builds/${encode(id)}/store-build`, {
246
+ body: mark,
247
+ requiredRoute: "native build store mark"
248
+ }),
249
+ listIosDevices: async ({ status, ...input }) => await call("GET", "/ios-devices", {
250
+ query: {
251
+ ...keysetParams(input),
252
+ ...status === void 0 ? {} : { status }
253
+ },
254
+ requiredRoute: "iOS device registry"
255
+ }) ?? [],
256
+ findIosDevice: (udid) => call("GET", `/ios-devices/udid/${encode(udid)}`, { requiredRoute: "iOS device registry" }),
257
+ requestIosDevice: async (input) => await call("POST", "/ios-devices", {
258
+ body: input,
259
+ requiredRoute: "iOS device registry"
260
+ }),
261
+ approveIosDevice: (id, input) => call("POST", `/ios-devices/${encode(id)}/approval`, {
262
+ body: input,
263
+ requiredRoute: "iOS device registry"
264
+ }),
265
+ renameIosDevice: (id, name) => call("PATCH", `/ios-devices/${encode(id)}`, {
266
+ body: { name },
267
+ requiredRoute: "iOS device registry"
268
+ }),
269
+ recordIosDeviceOutcome: ({ id, ...input }) => call("POST", `/ios-devices/${encode(id)}/outcome`, {
270
+ body: input,
271
+ requiredRoute: "iOS device registry"
272
+ }),
273
+ markIosDevicesInBuild: async (input) => {
274
+ await request("POST", "/ios-devices/in-build", {
275
+ body: input,
276
+ requiredRoute: "iOS device registry"
277
+ });
278
+ },
279
+ claimIosDeviceAccount: async (issuerId) => await call("POST", "/ios-devices/account", {
280
+ body: { issuerId },
281
+ requiredRoute: "iOS device registry"
282
+ }),
283
+ deleteIosDevice: (id, only) => call("DELETE", `/ios-devices/${encode(id)}`, {
284
+ query: {
285
+ ...only?.status === void 0 ? {} : { status: only.status },
286
+ ...only?.requestedBy === void 0 ? {} : { requestedBy: only.requestedBy }
287
+ },
288
+ requiredRoute: "iOS device registry"
289
+ }),
238
290
  deleteNativeBuild: async (id) => await call("DELETE", `/native-builds/${encode(id)}`, { requiredRoute: "native build deletion" })
239
291
  };
240
292
  };
@@ -251,8 +303,8 @@ const standaloneRepository = (config) => {
251
303
  return Object.freeze({
252
304
  name: "standalone-repository",
253
305
  core: createStandaloneCoreApi(config),
254
- fetchAdmin: (path, init = {}) => {
255
- const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
306
+ fetchAdmin: async (path, init = {}) => {
307
+ const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
256
308
  new Headers(init.headers).forEach((value, name) => {
257
309
  headers.set(name, value);
258
310
  });
@@ -269,8 +321,12 @@ const defaultRoutes = {
269
321
  put: () => ({ path: "/upload" }),
270
322
  get: () => ({ path: "/get" }),
271
323
  exists: () => ({ path: "/exists" }),
272
- delete: () => ({ path: "/delete" })
324
+ delete: () => ({ path: "/delete" }),
325
+ listObjects: () => ({ path: "/list" }),
326
+ deleteObjects: () => ({ path: "/delete-objects" })
273
327
  };
328
+ /** Keys sent in one `deleteObjects` request. */
329
+ const DELETE_BATCH_SIZE = 1e3;
274
330
  const createRoute = (defaultRoute, customRoute) => ({
275
331
  path: customRoute?.path ?? defaultRoute.path,
276
332
  headers: {
@@ -279,8 +335,8 @@ const createRoute = (defaultRoute, customRoute) => ({
279
335
  }
280
336
  });
281
337
  const standaloneStorage = (config) => {
282
- const getHeaders = (routeHeaders) => ({
283
- ...config.commonHeaders,
338
+ const getHeaders = async (routeHeaders) => ({
339
+ ...await resolveHeaders(config.commonHeaders),
284
340
  ...routeHeaders
285
341
  });
286
342
  const resolveRoute = (name, args) => {
@@ -288,6 +344,14 @@ const standaloneStorage = (config) => {
288
344
  const custom = config.routes?.[name];
289
345
  return createRoute(fallback(...args), custom?.(...args));
290
346
  };
347
+ const postJson = async (path, headers, body) => fetch(`${config.baseUrl}${path}`, {
348
+ method: "POST",
349
+ headers: {
350
+ "content-type": "application/json",
351
+ ...await getHeaders(headers)
352
+ },
353
+ body: JSON.stringify(body)
354
+ });
291
355
  const requestStorageUri = async (routeName, storageUri) => {
292
356
  parseStorageUri(storageUri, config.protocol);
293
357
  const { path, headers } = resolveRoute(routeName, [{ storageUri }]);
@@ -295,7 +359,7 @@ const standaloneStorage = (config) => {
295
359
  method: routeName === "delete" ? "DELETE" : "POST",
296
360
  headers: {
297
361
  "content-type": "application/json",
298
- ...getHeaders(headers)
362
+ ...await getHeaders(headers)
299
363
  },
300
364
  body: JSON.stringify({ storageUri })
301
365
  });
@@ -318,7 +382,7 @@ const standaloneStorage = (config) => {
318
382
  formData.append("key", key);
319
383
  const response = await fetch(`${config.baseUrl}${path}`, {
320
384
  method: "POST",
321
- headers: getHeaders(headers),
385
+ headers: await getHeaders(headers),
322
386
  body: formData
323
387
  });
324
388
  if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
@@ -339,6 +403,39 @@ const standaloneStorage = (config) => {
339
403
  async delete({ storageUri }) {
340
404
  await requestStorageUri("delete", storageUri);
341
405
  return { deleted: true };
406
+ },
407
+ async listObjects(prefix) {
408
+ const { path, headers } = resolveRoute("listObjects", [{ prefix }]);
409
+ const objects = [];
410
+ let cursor;
411
+ do {
412
+ const response = await postJson(path, headers, {
413
+ prefix,
414
+ cursor
415
+ });
416
+ if (response.status === 404) throw new Error(`The storage service has no ${path} route, which storage prune needs.`);
417
+ if (!response.ok) throw new Error(`Failed to list storage objects: ${response.statusText}`);
418
+ const page = await response.json();
419
+ for (const object of page.objects) {
420
+ parseStorageUri(object.storageUri, config.protocol);
421
+ objects.push({
422
+ key: object.key,
423
+ storageUri: object.storageUri,
424
+ size: object.size,
425
+ ...object.lastModifiedAt === void 0 ? {} : { lastModifiedAt: new Date(object.lastModifiedAt) }
426
+ });
427
+ }
428
+ cursor = page.cursor;
429
+ } while (cursor !== void 0);
430
+ return objects;
431
+ },
432
+ async deleteObjects(keys) {
433
+ for (let offset = 0; offset < keys.length; offset += DELETE_BATCH_SIZE) {
434
+ const batch = keys.slice(offset, offset + DELETE_BATCH_SIZE);
435
+ const { path, headers } = resolveRoute("deleteObjects", [{ keys: batch }]);
436
+ const response = await postJson(path, headers, { keys: batch });
437
+ if (!response.ok) throw new Error(`Failed to delete storage objects: ${response.statusText}`);
438
+ }
342
439
  }
343
440
  });
344
441
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/standalone",
3
- "version": "1.2.0-rc.3",
3
+ "version": "1.2.0-rc.31",
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.3",
46
- "@hot-updater/plugin-core": "1.2.0-rc.3"
45
+ "@hot-updater/plugin-core": "1.2.0-rc.31",
46
+ "@hot-updater/protocol": "1.2.0-rc.31"
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.3"
56
- },
57
- "nx": {
58
- "implicitDependencies": [
59
- "!@hot-updater/test-utils"
60
- ]
55
+ "@hot-updater/test-utils": "1.2.0-rc.31"
61
56
  },
62
57
  "scripts": {
63
58
  "build": "tsdown",