@hot-updater/react-native 1.0.0-rc.28 → 1.0.0-rc.29
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/lib/commonjs/fetchJSON.js +12 -26
- package/lib/commonjs/fetchJSON.js.map +1 -1
- package/lib/commonjs/fetchUpdateResponse.js +54 -0
- package/lib/commonjs/fetchUpdateResponse.js.map +1 -0
- package/lib/commonjs/httpClient.js +9 -3
- package/lib/commonjs/httpClient.js.map +1 -1
- package/lib/commonjs/index.js +6 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/releaseCatalogCache.js +17 -27
- package/lib/commonjs/releaseCatalogCache.js.map +1 -1
- package/lib/commonjs/sdkVersion.js +1 -1
- package/lib/module/clientPlugin.js.map +1 -1
- package/lib/module/fetchJSON.js +12 -26
- package/lib/module/fetchJSON.js.map +1 -1
- package/lib/module/fetchUpdateResponse.js +49 -0
- package/lib/module/fetchUpdateResponse.js.map +1 -0
- package/lib/module/httpClient.js +9 -3
- package/lib/module/httpClient.js.map +1 -1
- package/lib/module/index.js +6 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/releaseCatalogCache.js +17 -27
- package/lib/module/releaseCatalogCache.js.map +1 -1
- package/lib/module/sdkVersion.js +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts +1 -1
- package/lib/typescript/commonjs/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/commonjs/fetchJSON.d.ts +2 -5
- package/lib/typescript/commonjs/fetchJSON.d.ts.map +1 -1
- package/lib/typescript/commonjs/fetchUpdateResponse.d.ts +14 -0
- package/lib/typescript/commonjs/fetchUpdateResponse.d.ts.map +1 -0
- package/lib/typescript/commonjs/httpClient.d.ts +2 -2
- package/lib/typescript/commonjs/httpClient.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -1
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/releaseCatalogCache.d.ts +2 -0
- package/lib/typescript/commonjs/releaseCatalogCache.d.ts.map +1 -1
- package/lib/typescript/commonjs/sdkVersion.d.ts +1 -1
- package/lib/typescript/module/clientPlugin.d.ts +1 -1
- package/lib/typescript/module/clientPlugin.d.ts.map +1 -1
- package/lib/typescript/module/fetchJSON.d.ts +2 -5
- package/lib/typescript/module/fetchJSON.d.ts.map +1 -1
- package/lib/typescript/module/fetchUpdateResponse.d.ts +14 -0
- package/lib/typescript/module/fetchUpdateResponse.d.ts.map +1 -0
- package/lib/typescript/module/httpClient.d.ts +2 -2
- package/lib/typescript/module/httpClient.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -1
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/releaseCatalogCache.d.ts +2 -0
- package/lib/typescript/module/releaseCatalogCache.d.ts.map +1 -1
- package/lib/typescript/module/sdkVersion.d.ts +1 -1
- package/package.json +3 -3
- package/src/clientPlugin.ts +1 -0
- package/src/fetchJSON.ts +11 -31
- package/src/fetchUpdateResponse.ts +54 -0
- package/src/httpClient.ts +10 -2
- package/src/index.ts +7 -2
- package/src/releaseCatalogCache.ts +23 -38
- package/src/sdkVersion.ts +1 -1
package/src/index.ts
CHANGED
|
@@ -57,6 +57,7 @@ export {
|
|
|
57
57
|
type UpdateError,
|
|
58
58
|
type UpdateErrorReason,
|
|
59
59
|
type UpdateErrorStage,
|
|
60
|
+
type UpdateHttpResponse,
|
|
60
61
|
type UpdateStrategy,
|
|
61
62
|
} from "./clientPlugin";
|
|
62
63
|
// The built-in Insights client plugin, for HotUpdater.init({ plugins }).
|
|
@@ -181,7 +182,9 @@ function createHotUpdaterClient() {
|
|
|
181
182
|
const { baseURL, plugins: _plugins, ...rest } = autoOptions;
|
|
182
183
|
return {
|
|
183
184
|
...rest,
|
|
184
|
-
client: createHttpClient(baseURL)
|
|
185
|
+
client: createHttpClient(baseURL, (response) => {
|
|
186
|
+
emitAfterAppReady("onHttpResponse", () => response);
|
|
187
|
+
}),
|
|
185
188
|
};
|
|
186
189
|
}
|
|
187
190
|
|
|
@@ -200,7 +203,9 @@ function createHotUpdaterClient() {
|
|
|
200
203
|
const { baseURL, plugins: _plugins, ...baseURLRest } = rest;
|
|
201
204
|
return {
|
|
202
205
|
...baseURLRest,
|
|
203
|
-
client: createHttpClient(baseURL)
|
|
206
|
+
client: createHttpClient(baseURL, (response) => {
|
|
207
|
+
emitAfterAppReady("onHttpResponse", () => response);
|
|
208
|
+
}),
|
|
204
209
|
};
|
|
205
210
|
}
|
|
206
211
|
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type ReleaseCatalog,
|
|
7
7
|
} from "@hot-updater/protocol";
|
|
8
8
|
|
|
9
|
+
import { fetchUpdateResponse, type UpdateRequest } from "./fetchUpdateResponse";
|
|
9
10
|
import { InvalidUpdateResponseError, UpdateHttpError } from "./updateError";
|
|
10
11
|
|
|
11
12
|
const CACHE_FORMAT_VERSION = "1";
|
|
@@ -50,6 +51,7 @@ type FetchReleaseCatalogInput = {
|
|
|
50
51
|
readonly requestHeaders?: Record<string, string>;
|
|
51
52
|
readonly requestTimeout?: number;
|
|
52
53
|
readonly url: string;
|
|
54
|
+
readonly onResponse?: UpdateRequest["onResponse"];
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
const isValidETag = (value: string | null): value is string =>
|
|
@@ -113,36 +115,24 @@ export const createReleaseCatalogCachePartition = (
|
|
|
113
115
|
version: 2,
|
|
114
116
|
});
|
|
115
117
|
|
|
116
|
-
const
|
|
118
|
+
const isEmptyCatalogResponse = (response: Response) =>
|
|
119
|
+
response.status === 404 &&
|
|
120
|
+
response.headers.get("x-hot-updater-catalog")?.trim().toLowerCase() ===
|
|
121
|
+
"none";
|
|
122
|
+
|
|
123
|
+
const fetchCatalogResponse = (
|
|
117
124
|
input: FetchReleaseCatalogInput,
|
|
118
125
|
etag?: string,
|
|
119
|
-
)
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (etag === undefined) {
|
|
130
|
-
headers.delete("If-None-Match");
|
|
131
|
-
} else {
|
|
132
|
-
headers.set("If-None-Match", etag);
|
|
133
|
-
}
|
|
134
|
-
return await fetch(input.url, {
|
|
135
|
-
headers,
|
|
136
|
-
signal: controller.signal,
|
|
137
|
-
});
|
|
138
|
-
} catch (error: unknown) {
|
|
139
|
-
if (error instanceof Error && error.name === "AbortError") {
|
|
140
|
-
throw new Error("Request timed out");
|
|
141
|
-
}
|
|
142
|
-
throw error;
|
|
143
|
-
} finally {
|
|
144
|
-
clearTimeout(timeoutId);
|
|
145
|
-
}
|
|
126
|
+
) => {
|
|
127
|
+
const headers = new Headers(input.requestHeaders);
|
|
128
|
+
headers.set("Accept", "application/json");
|
|
129
|
+
if (etag === undefined) headers.delete("If-None-Match");
|
|
130
|
+
else headers.set("If-None-Match", etag);
|
|
131
|
+
return fetchUpdateResponse({
|
|
132
|
+
...input,
|
|
133
|
+
resource: "catalog",
|
|
134
|
+
requestHeaders: Object.fromEntries(headers.entries()),
|
|
135
|
+
});
|
|
146
136
|
};
|
|
147
137
|
|
|
148
138
|
const readValidatedCache = async (
|
|
@@ -160,25 +150,20 @@ const readValidatedCache = async (
|
|
|
160
150
|
};
|
|
161
151
|
|
|
162
152
|
const consumeSuccessfulResponse = async (
|
|
163
|
-
response:
|
|
153
|
+
{ response, body }: Awaited<ReturnType<typeof fetchCatalogResponse>>,
|
|
164
154
|
input: FetchReleaseCatalogInput,
|
|
165
155
|
partition: string,
|
|
166
156
|
): Promise<ReleaseCatalog | null> => {
|
|
167
157
|
// The server marks the 404 of a scope that has no catalog yet: no update,
|
|
168
158
|
// not a failure. Any other 404 is a wrong baseURL or route.
|
|
169
|
-
if (
|
|
170
|
-
response.status === 404 &&
|
|
171
|
-
response.headers.get("x-hot-updater-catalog")?.trim().toLowerCase() ===
|
|
172
|
-
"none"
|
|
173
|
-
) {
|
|
159
|
+
if (isEmptyCatalogResponse(response)) {
|
|
174
160
|
return null;
|
|
175
161
|
}
|
|
176
162
|
if (response.status !== 200) {
|
|
177
163
|
throw new UpdateHttpError(response.status, response.statusText);
|
|
178
164
|
}
|
|
179
165
|
|
|
180
|
-
const
|
|
181
|
-
const catalog = parseReleaseCatalog(body, input.expectedScope);
|
|
166
|
+
const catalog = parseReleaseCatalog(body!, input.expectedScope);
|
|
182
167
|
if (catalog === null) {
|
|
183
168
|
await removeNativeReleaseCatalogCache(partition);
|
|
184
169
|
throw new InvalidUpdateResponseError("Received an invalid Release catalog");
|
|
@@ -186,7 +171,7 @@ const consumeSuccessfulResponse = async (
|
|
|
186
171
|
|
|
187
172
|
const etag = response.headers.get("etag");
|
|
188
173
|
if (isValidETag(etag)) {
|
|
189
|
-
const serialized = serializeCache(etag, body);
|
|
174
|
+
const serialized = serializeCache(etag, body!);
|
|
190
175
|
if (getUtf8ByteLength(serialized) > MAX_RELEASE_CATALOG_CACHE_ENTRY_BYTES) {
|
|
191
176
|
await removeNativeReleaseCatalogCache(partition);
|
|
192
177
|
return catalog;
|
|
@@ -216,7 +201,7 @@ export const fetchReleaseCatalogWithCache = async (
|
|
|
216
201
|
const cached = await readValidatedCache(partition, input.expectedScope);
|
|
217
202
|
const response = await fetchCatalogResponse(input, cached?.etag);
|
|
218
203
|
|
|
219
|
-
if (response.status === 304) {
|
|
204
|
+
if (response.response.status === 304) {
|
|
220
205
|
if (cached !== null) return cached.catalog;
|
|
221
206
|
|
|
222
207
|
const repairResponse = await fetchCatalogResponse(input);
|
package/src/sdkVersion.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const HOT_UPDATER_SDK_VERSION = "1.0.0-rc.
|
|
1
|
+
export const HOT_UPDATER_SDK_VERSION = "1.0.0-rc.29";
|