@hot-updater/standalone 1.2.0-rc.7 → 1.2.0-rc.8

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) => {
@@ -108,7 +110,7 @@ const createStandaloneCoreApi = (config) => {
108
110
  const http = createStandaloneHttp(config);
109
111
  let checked;
110
112
  const checkProtocol = async () => {
111
- 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" }) });
112
114
  const body = response.status === 404 ? {} : await http.parseJson(response);
113
115
  const protocol = isRecord(body) ? body.adminProtocol : void 0;
114
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);
@@ -125,7 +127,7 @@ const createStandaloneCoreApi = (config) => {
125
127
  for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
126
128
  const response = await fetch(url, {
127
129
  method,
128
- headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
130
+ headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
129
131
  ...body === void 0 ? {} : { body: JSON.stringify(body) }
130
132
  });
131
133
  if (response.status === 204) return null;
@@ -252,8 +254,8 @@ const standaloneRepository = (config) => {
252
254
  return Object.freeze({
253
255
  name: "standalone-repository",
254
256
  core: createStandaloneCoreApi(config),
255
- fetchAdmin: (path, init = {}) => {
256
- const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
257
+ fetchAdmin: async (path, init = {}) => {
258
+ const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
257
259
  new Headers(init.headers).forEach((value, name) => {
258
260
  headers.set(name, value);
259
261
  });
@@ -280,8 +282,8 @@ const createRoute = (defaultRoute, customRoute) => ({
280
282
  }
281
283
  });
282
284
  const standaloneStorage = (config) => {
283
- const getHeaders = (routeHeaders) => ({
284
- ...config.commonHeaders,
285
+ const getHeaders = async (routeHeaders) => ({
286
+ ...await resolveHeaders(config.commonHeaders),
285
287
  ...routeHeaders
286
288
  });
287
289
  const resolveRoute = (name, args) => {
@@ -296,7 +298,7 @@ const standaloneStorage = (config) => {
296
298
  method: routeName === "delete" ? "DELETE" : "POST",
297
299
  headers: {
298
300
  "content-type": "application/json",
299
- ...getHeaders(headers)
301
+ ...await getHeaders(headers)
300
302
  },
301
303
  body: JSON.stringify({ storageUri })
302
304
  });
@@ -319,7 +321,7 @@ const standaloneStorage = (config) => {
319
321
  formData.append("key", key);
320
322
  const response = await fetch(`${config.baseUrl}${path}`, {
321
323
  method: "POST",
322
- headers: getHeaders(headers),
324
+ headers: await getHeaders(headers),
323
325
  body: formData
324
326
  });
325
327
  if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
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, 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
@@ -53,7 +57,12 @@ interface StandaloneStorageConfig {
53
57
  baseUrl: string;
54
58
  /** Storage URI protocol owned by the remote implementation. */
55
59
  protocol: string;
56
- commonHeaders?: Record<string, string>;
60
+ /**
61
+ * Headers sent with every request. A value may be a function that returns
62
+ * it, such as `secret("<name>")` in `hot-updater.config.ts`, called on
63
+ * the first request.
64
+ */
65
+ commonHeaders?: Record<string, Lazy<string>>;
57
66
  routes?: Partial<StorageRoutes>;
58
67
  }
59
68
  declare const standaloneStorage: (config: StandaloneStorageConfig) => {
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, 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
@@ -53,7 +57,12 @@ interface StandaloneStorageConfig {
53
57
  baseUrl: string;
54
58
  /** Storage URI protocol owned by the remote implementation. */
55
59
  protocol: string;
56
- commonHeaders?: Record<string, string>;
60
+ /**
61
+ * Headers sent with every request. A value may be a function that returns
62
+ * it, such as `secret("<name>")` in `hot-updater.config.ts`, called on
63
+ * the first request.
64
+ */
65
+ commonHeaders?: Record<string, Lazy<string>>;
57
66
  routes?: Partial<StorageRoutes>;
58
67
  }
59
68
  declare const standaloneStorage: (config: StandaloneStorageConfig) => {
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) => {
@@ -107,7 +109,7 @@ const createStandaloneCoreApi = (config) => {
107
109
  const http = createStandaloneHttp(config);
108
110
  let checked;
109
111
  const checkProtocol = async () => {
110
- const response = await fetch(http.buildUrl("/version"), { headers: http.headers({ "Cache-Control": "no-cache" }) });
112
+ const response = await fetch(http.buildUrl("/version"), { headers: await http.headers({ "Cache-Control": "no-cache" }) });
111
113
  const body = response.status === 404 ? {} : await http.parseJson(response);
112
114
  const protocol = isRecord(body) ? body.adminProtocol : void 0;
113
115
  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 +126,7 @@ const createStandaloneCoreApi = (config) => {
124
126
  for (const [key, value] of Object.entries(query)) url.searchParams.set(key, value);
125
127
  const response = await fetch(url, {
126
128
  method,
127
- headers: http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
129
+ headers: await http.headers(method === "GET" ? { "Cache-Control": "no-cache" } : void 0),
128
130
  ...body === void 0 ? {} : { body: JSON.stringify(body) }
129
131
  });
130
132
  if (response.status === 204) return null;
@@ -251,8 +253,8 @@ const standaloneRepository = (config) => {
251
253
  return Object.freeze({
252
254
  name: "standalone-repository",
253
255
  core: createStandaloneCoreApi(config),
254
- fetchAdmin: (path, init = {}) => {
255
- const headers = new Headers(http.headers({ "Cache-Control": "no-cache" }));
256
+ fetchAdmin: async (path, init = {}) => {
257
+ const headers = new Headers(await http.headers({ "Cache-Control": "no-cache" }));
256
258
  new Headers(init.headers).forEach((value, name) => {
257
259
  headers.set(name, value);
258
260
  });
@@ -279,8 +281,8 @@ const createRoute = (defaultRoute, customRoute) => ({
279
281
  }
280
282
  });
281
283
  const standaloneStorage = (config) => {
282
- const getHeaders = (routeHeaders) => ({
283
- ...config.commonHeaders,
284
+ const getHeaders = async (routeHeaders) => ({
285
+ ...await resolveHeaders(config.commonHeaders),
284
286
  ...routeHeaders
285
287
  });
286
288
  const resolveRoute = (name, args) => {
@@ -295,7 +297,7 @@ const standaloneStorage = (config) => {
295
297
  method: routeName === "delete" ? "DELETE" : "POST",
296
298
  headers: {
297
299
  "content-type": "application/json",
298
- ...getHeaders(headers)
300
+ ...await getHeaders(headers)
299
301
  },
300
302
  body: JSON.stringify({ storageUri })
301
303
  });
@@ -318,7 +320,7 @@ const standaloneStorage = (config) => {
318
320
  formData.append("key", key);
319
321
  const response = await fetch(`${config.baseUrl}${path}`, {
320
322
  method: "POST",
321
- headers: getHeaders(headers),
323
+ headers: await getHeaders(headers),
322
324
  body: formData
323
325
  });
324
326
  if (!response.ok) throw new Error(`Failed to upload bundle: ${response.statusText}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/standalone",
3
- "version": "1.2.0-rc.7",
3
+ "version": "1.2.0-rc.8",
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.7",
46
- "@hot-updater/plugin-core": "1.2.0-rc.7"
45
+ "@hot-updater/protocol": "1.2.0-rc.8",
46
+ "@hot-updater/plugin-core": "1.2.0-rc.8"
47
47
  },
48
48
  "devDependencies": {
49
49
  "mime": "2.6.0",
@@ -52,7 +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.7"
55
+ "@hot-updater/test-utils": "1.2.0-rc.8"
56
56
  },
57
57
  "nx": {
58
58
  "implicitDependencies": [